********************************************************************************
* Figure 1: # Bonds issues and Merger covenants
********************************************************************************
clear
use fisdSample_at_issue
	keep if in_compu==1
collapse (count) noBond=issue_id (mean) inv_res_umb div_res_umb sub_fin_res_umb event_res_umb merger_res control_change_res event_res, by(yr)
	drop if noBond==.
	keep if yr>1979
	local vars inv_res_umb div_res_umb sub_fin_res_umb event_res_umb merger_res control_change_res
	foreach v of local vars{
		replace `v'=`v'*100
	}
	la var noBond "# Bonds"
	la var inv_res_umb "Investment"
	la var div_res_umb "Dividend"
	la var sub_fin_res_umb "Sub. Financing"
	la var event_res_umb "Event"	
	la var merger_res "Merger"
	la var control_change_res "Change in Control"
	
twoway bar noBond yr, fcolor(gs14)   ytitle("# Bonds issued", axis(2)) yaxis(2) yscale(axis(2)) xsc(r(1980 2018)) xlabel(1980[5]2018) ///
	|| line merger_res yr, ytitle("% bonds with restrictions", axis(1)) xsc(r(1980 2018)) xlabel(1980[5]2018)	///
	|| , title("Bonds issued and Covenants ")
graph export "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\figures\newDebt_merger_cov.eps", replace		



********************************************************************************
* TABLE 1: Sample distribution of bond repurchase and covenants
********************************************************************************
clear
use fisdSample_MnA_TRACE_cov_grpd
la var div_res_umb "{Dividend-related Restrictions}"
keep if repurchase==1
    local vars 	inv_res_umb merger_res  direct_inv_res other_Inv_res ///
				div_res_umb ///
				sub_fin_res_umb  ///
				event_res_umb control_change_res other_event_res 
	local opt "replace"
	tempname hh
	file open `hh' using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\tables\covenant_dist_allRep_grp.tex", write `opt'
	file write `hh' "\begin{tabular}{l*{3}{l}} \hline \hline" _n
	file write `hh' " {Variable} & {Mean} & {SD} & {N} \\ \hline " _n
	
	foreach v of local vars {
	local label : variable label `v'	
	if "`v'" == "div_res_umb"{
		file write `hh' "\\" _n
	}
	if "`v'" == "sub_fin_res_umb"{
		file write `hh' "\\" _n
	}
	if "`v'" == "event_res_umb"{
		file write `hh' "\\" _n
	}
	
	file write `hh' "`label'" " & "
	
	qui summarize `v' , d
	file write `hh' %9.2fc (r(mean)) " & "
	*file write `hh' %9.2fc (r(p50)) " & "
	*file write `hh' %9.2fc (r(p25)) " & "
	file write `hh' %9.2fc (r(sd)) " & "
	*file write `hh' %9.2fc (r(p75)) " & "
	file write `hh' %9.0fc (r(N)) " \\ " _n
	}
	file write `hh' "\hline \end{tabular}"  _n
	file close `hh'	



********************************************************************************
* Table 2:  DiD Bond repurchase and M&A - Triple interaction
********************************************************************************	
cd "D:\Dropbox\Datasets\TRACE\data"

clear
use gvkey atq lev ret1Qtr calYrQtr chq_at tobinsq using compuQtrly
tempfile compuData
save `compuData'


clear
use repCS_b4Aftr_wFin
	keep issuer_id	permco	gvkey indCode
	duplicates drop
tempfile indCodes
save `indCodes'

* SAMPLE MATCHING
clear
use matchedAcqReps_repMth
	duplicates drop 	
	rename (calYrQtr_ef openMrkt) (repYrQtr openMrkt_rep_dum)
tempfile matchedReps
save `matchedReps'

clear
use frmYrQtrPanel_repSample	
	gen openMrkt_rep_dum=cond(openMrkt_rep>0&tenderOffer_rep==0,1,0)
	joinby issuer_id gvkey repYrQtr openMrkt_rep_dum using `matchedReps'
	drop openMrkt_rep_dum
	gen fyear=yofd(dofq(calYrQtr))
	merge m:1 gvkey calYrQtr using `compuData', keepusing(atq lev cash_at tobinsq )
	drop if _merge==2
	drop _merge
	gen ln_atq_ =ln(1+atq)
	gen tenderDum=cond(tenderOffer_rep>0,1,0)
	gen post = cond(timeLine>0,1,0)
	
	sort issuer_id permco gvkey repYrQtr timeLine
	local vars inv_res_umb_frac div_res_umb_frac sub_fin_res_umb_frac event_res_umb_frac merger_res_frac lev cash_at
	foreach v of local vars{
		by issuer_id permco gvkey repYrQtr: gen diff_`v'=`v'-`v'[_n-1]
	}

	sort issuer_id permco gvkey repYrQtr repEventID timeLine
	by issuer_id permco gvkey repYrQtr repEventID: egen postAcqrr=sum(acq_dum) if timeLine>0
	replace postAcqrr=0 if postAcqrr==.
	gen postAcq=post*acq_dum 
	gen postTender=post*tenderDum
	gen postTenderAcq=post*tenderDum*acq_dum
	gen acqTender=acq_dum*tenderDum
	merge m:1 issuer_id	permco	gvkey using `indCodes', keepusing(indCode)
	drop if _merge==2
	drop _merge
	
	la var tenderDum "Tender Offer"
	la var post "Post"
	la var postAcq "Post \$ \times \$ Acquirer"
	la var postTender "Post \$ \times \$ Tender Offer"
	la var postTenderAcq "Post \$ \times \$ Tender Offer \$ \times \$ Acquirer"
	la var acq_dum "Acquirer"
	la var acqTender "Tender Offer \$ \times \$ Acquirer"
		
	la var diff_inv_res_umb_frac "Investment"
	la var diff_div_res_umb_frac "Dividend"
	la var diff_sub_fin_res_umb_frac "Subsequent Financing"
	la var diff_event_res_umb_frac "Event"
	la var diff_merger_res_frac "Merger"
	la var diff_lev "Leverage"
	la var diff_cash_at "(Cash/Total Assets)"

	la var inv_res_umb_frac "Investment"
	la var div_res_umb_frac "Dividend"
	la var sub_fin_res_umb_frac "Subsequent Financing"
	la var event_res_umb_frac "Event"
	la var merger_res_frac "Merger"
	la var lev "Leverage"
	la var cash_at "(Cash/Total Assets)"

	la var indirect_Inv_Res_frac "Indirect Investment"
	la var stock_sale_res_frac "Stock Sale"
	la var direct_inv_res_frac "Direct Investment"
	la var inv_res_frac "Investment"
	la var secured_frac "Secured"
	la var div_pay_res_frac "Dividend Payment"
	la var other_pay_res_frac "Other Payment"
	la var subord_deb_issue_res_frac "Subord. Debt Issue"
	la var saleLease_ob_res_frac "Sale/Lease Obligation"
	la var debt_priority_res_frac "Debt Priority"
	la var stock_iss_res_frac "Stock Issuance"
	la var default_res_frac "Default"
	la var control_change_res_frac "Change in Control"
	la var event_res_frac "Events"	
	la var ln_atq_ef "Ln(1+Total Assets\$  _{t-1} \$)"
	la var lev "Leverage\$  _{t-1} \$ "
		
	duplicates drop repEventID issuer_id permco gvkey timeLine, force
	egen firmID=group(repEventID issuer_id permco gvkey)
	tsset firmID timeLine 
	drop if timeLine==-9

save cov_ma_3did	

use cov_ma_3did, clear
estimates clear	
	qui eststo:	areg merger_res_frac post tenderDum acq_dum  postTender postAcq acqTender postTenderAcq l.ln_atq l.lev l.cash_at l.tobinsq    i.calYrQtr  ,  a(gvkey) r cl(indCode) 
	estadd scalar obs = 34164
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	estadd local repFE "\$ \checkmark \$"
		
	qui eststo:	areg inv_res_umb_frac post tenderDum acq_dum  postTender postAcq acqTender postTenderAcq l.ln_atq l.lev l.cash_at l.tobinsq   i.calYrQtr    ,  a(gvkey) r cl(indCode) 
	estadd scalar obs = 34164
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	estadd local repFE "\$ \checkmark \$"

	qui eststo:	areg div_res_umb_frac post tenderDum acq_dum  postTender postAcq acqTender postTenderAcq l.ln_atq l.lev l.cash_at l.tobinsq   i.calYrQtr    ,  a(gvkey) r cl(indCode) 
	estadd scalar obs = 34164
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	estadd local repFE "\$ \checkmark \$"

	qui eststo:	areg sub_fin_res_umb_frac post tenderDum acq_dum  postTender postAcq acqTender postTenderAcq l.ln_atq l.lev l.cash_at l.tobinsq   i.calYrQtr    ,  a(gvkey) r cl(indCode) 
	estadd scalar obs = 34164
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	estadd local repFE "\$ \checkmark \$"

	qui eststo:	areg control_change_res_frac post tenderDum acq_dum  postTender postAcq acqTender postTenderAcq l.ln_atq l.lev l.cash_at l.tobinsq  i.calYrQtr    ,  a(gvkey) r cl(indCode) 
	estadd scalar obs = 34164
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	estadd local repFE "\$ \checkmark \$"
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\tables\covenant_n_MnA_pnl_ctrls_mtch1_ind.tex", replace  b(3) se(3)  ///
		keep( post tenderDum acq_dum  postTender postAcq acqTender postTenderAcq    ) ///
		order( post tenderDum acq_dum  postTender postAcq acqTender postTenderAcq   ) ///
		depvars  label stats(obs rsqA firmFE yrFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
		labels("Obs." "$ Adj.-R^{2} $" "Firm F.E." "Qtr. F.E." )) ///			
		substitute(\_ _) star(* .1 ** .05 *** .01)	
		
		
	
********************************************************************************
* Table 3 and 9: Covenant redesign and competitiveness of industry | Cross-sectional regressions: change in covenants, M&A activity, and competition
********************************************************************************		

use "D:\Dropbox\Datasets\TRACE\data\sdcMnA_linked_1990_2019_ind.dta" , clear
	gen internet=0
	replace internet=1 if acqindsector=="Advertising Services"|	acqindsector=="Air Transportation and Shipping"|	acqindsector=="Amusement and Recreation Services"|	acqindsector=="Business Services"|	acqindsector=="Commercial Banks, Bank Holding Companies"|	acqindsector=="Computer and Office Equipment"|	acqindsector=="Credit Institutions"|	acqindsector=="Educational Services"|	acqindsector=="Insurance"|	acqindsector=="Investment & Commodity Firms,Dealers,Exchanges"|	acqindsector=="Legal Services"|	acqindsector=="Motion Picture Production and Distribution"|	acqindsector=="Other Financial"|	acqindsector=="Prepackaged Software"|	acqindsector=="Printing, Publishing, and Allied Services"|	acqindsector=="Radio and Television Broadcasting Stations"|	acqindsector=="Real Estate; Mortgage Bankers and Brokers"|	acqindsector=="Savings and Loans, Mutual Savings Banks"	
	collapse (sum) internet (count) no_acq=acq_indCode, by(acqprisic yr)	
	replace internet=1 if internet>0	
	keep if internet==1
	gen sic=real(acqprisic)
	drop if sic==.
	keep sic internet
	duplicates drop 
tempfile internet_sics	
save `internet_sics'


* Identify cross country/industry deals from the SDC dataset
clear
use sdcMnA_linked_1990_2019_ind
append using sdcMnA_linked_1990_2022_ind
	gen cross_country=cond(trim(lower(acqnation))!=trim(lower(trgtnation)),1,0)
	tab cross_country
	keep permco_acq permco_trgt gvkey_acq gvkey_trgt  dateannounced diff_sic4 diff_sic3 cross_country
	gen calYrQtr_ef=qofd(dateannounced)
	format %tq calYrQtr_ef
	gen deal=1
tempfile base_file	
save `base_file'
	collapse (sum) deal diff_sic4 diff_sic3 cross_country, by(permco_acq calYrQtr_ef)
	rename (permco_acq diff_sic4 diff_sic3 cross_country calYrQtr_ef deal) (permco diff_sic4_acq diff_sic3_acq cross_country_acq calYrQtr_ef_acq cross_acquirer)
tempfile acq_file	
save `acq_file'
use `base_file', clear
	collapse (sum) diff_sic4 diff_sic3 cross_country deal, by(permco_trgt gvkey_trgt calYrQtr_ef)
	rename (permco_trgt diff_sic4 diff_sic3 cross_country calYrQtr_ef deal) (permco diff_sic4_trg diff_sic3_trg cross_country_trg calYrQtr_ef_trg cross_target)
tempfile trg_file	
save `trg_file'
clear
use repCS_b4Aftr_wFin
	keep permco calYrQtr_ef
	duplicates drop 
	joinby permco using `acq_file'
	gen repB4MnA_acq=cond(calYrQtr_ef-calYrQtr_ef_acq>=0&calYrQtr_ef-calYrQtr_ef_acq<=8,1,0)
	keep if repB4MnA_acq==1
	collapse (sum) cross_acquirer diff_sic4_acq diff_sic3_acq cross_country_acq, by(permco calYrQtr_ef)
tempfile acq_within_2yrs	
save `acq_within_2yrs'
clear
use repCS_b4Aftr_wFin
	keep permco calYrQtr_ef
	duplicates drop 
	joinby permco using `trg_file'
	gen repB4MnA_trg=cond(calYrQtr_ef-calYrQtr_ef_trg>=0&calYrQtr_ef-calYrQtr_ef_trg<=8,1,0)
	keep if repB4MnA_trg==1
	collapse (sum) cross_target diff_sic4_trg diff_sic3_trg cross_country_trg, by(permco calYrQtr_ef)
tempfile trg_within_2yrs	
save `trg_within_2yrs'	


* Get NTR Gap
clear
set obs 20
	gen rep_yr=2001
	forvalues i=1(1)20{
		replace rep_yr=rep_yr+`i' if _n==`i'
	}
tempfile extra_yrs	
save `extra_yrs'
clear
import delimited D:\Dropbox\Datasets\TRACE\data\tariff\NTRgap_NAICSoriginal_PeterSchott_v2.csv
	replace sic =trim(sic)
	replace naics_code=trim(naics_code)
	gen sic1=real(sic)
	gen naics_code1=real(naics_code)
	drop sic naics_code
	rename (sic1 naics_code1 ) (sic4 naics_code )
	destring ntrgap, replace i('N' 'A')
	sort sic4 rep_yr	
	drop if sic4==.
	collapse (mean) ntrgap, by(sic4 rep_yr)
	append using `extra_yrs' 
	fillin sic4 rep_yr
	sort sic4 rep_yr
	tsset sic4 rep_yr
	replace ntrgap=l.ntrgap if ntrgap==.
	keep sic4 rep_yr ntrgap 
	rename (rep_yr sic4) (calYr sic)
tempfile ntrgap	
save `ntrgap'

clear
use wavePeriod
	gen calYrQtr_ef = yq(year(dofm(yrMth)), quarter(dofm(yrMth)))
	format %tq calYrQtr_ef
	drop yrMth
	duplicates drop 
tempfile wave	
save `wave'

* SAMPLE MATCHING
clear
use matchedAcqReps_repMth
	append using matchedTrgReps_repMth
	duplicates drop 	
tempfile matchedReps
save `matchedReps'

clear
use repCS_b4Aftr_wFin	
	joinby issuer_id gvkey calYrQtr_ef openMrkt using `matchedReps'
	sort repQtrID_1 issuer_id issue_id calYrQtr_ef 
	su atq_ef lev
	drop atq_ef lev   
	replace calYrQtr_ef=calYrQtr_ef-1
	gen fyear=yofd(dofq(calYrQtr_ef))
	merge m:1 gvkey calYrQtr_ef using compuData, keepusing(atq lev)
	drop if _merge==2
	drop _merge
	replace calYrQtr_ef=calYrQtr_ef+1
	merge m:1 gvkey fyear using compuDataYrly, keepusing(at_yrly lev_yrly)
	drop if _merge==2
	drop _merge
	
	bysort issuer_id calYrQtr_ef: egen acq=sum(repB4MnA_acq)
	replace acq=1 if acq>0
	sort  gvkey calYrQtr_ef 
	replace repB4MnA_acq=acq
	bysort issuer_id calYrQtr_ef: egen trg=sum(repB4MnA_trg)
	replace trg=1 if trg>0
	sort  gvkey calYrQtr_ef 
	replace repB4MnA_trg=trg
	drop trg acq
	
	su atq lev
	bysort issuer_id calYrQtr_ef: egen atq_ef = max(atq) 
	bysort issuer_id calYrQtr_ef: egen lev_ef = max(lev) 
	sort issuer_id calYrQtr_ef
	bysort issuer_id: ipolate atq_ef calYrQtr, g(atq_ipo)
	bysort issuer_id: ipolate lev_ef calYrQtr, g(lev_ipo)	
	su atq_ef lev_ef atq_ipo lev_ipo
	
	sort issuer_id fyear
	bysort issuer_id: ipolate at_yrly fyear, g(at_yrly_ipo)
	bysort issuer_id: ipolate lev_yrly fyear, g(lev_yrly_ipo)	
	replace atq_ipo=at_yrly_ipo if atq_ipo==.
	replace lev_ipo=lev_yrly_ipo if lev_ipo==.

	/*sort issuer_id calYrQtr_ef
	by issuer_id: replace atq_ipo=atq_ipo[_n-1] if atq_ipo==. & calYrQtr_ef-calYrQtr_ef[_n-1]<=4
	by issuer_id: replace lev_ipo=lev_ipo[_n-1] if lev_ipo==. & calYrQtr_ef-calYrQtr_ef[_n-1]<=4
	su atq_ef lev_ef atq_ipo lev_ipo
	*/
	local vars merger_res_frac_preQ inv_res_umb_frac_preQ div_res_umb_frac_preQ sub_fin_res_umb_frac_preQ event_res_umb_frac_preQ default_res_frac_preQ control_change_res_frac_preQ event_res_frac_preQ  ///
				nb_merger_res_frac nb_inv_res_umb_frac nb_div_res_umb_frac nb_sub_fin_res_umb_frac nb_event_res_umb_frac nb_default_res_frac nb_control_change_res_frac nb_event_res_frac
	foreach v of local vars{
		replace `v'=0 if `v'==.
	}
	gen calYr=yofd(dofq(calYrQtr_ef))
	gen ln_atq_ef =ln(1+atq_ipo)
	replace lev=ln(1+lev_ipo)

	gen diff_merger_res_frac=merger_res_frac_p2yr-merger_res_frac_preQ
	gen diff_inv_res_umb_frac=inv_res_umb_frac_p2yr-inv_res_umb_frac_preQ
	gen diff_div_res_umb_frac=div_res_umb_frac_p2yr-div_res_umb_frac_preQ 
	gen diff_sub_fin_res_umb_frac =sub_fin_res_umb_frac_p2yr-sub_fin_res_umb_frac_preQ
	gen diff_event_res_umb_frac=event_res_umb_frac_p2yr-event_res_umb_frac_preQ
	gen diff_default_res_frac=default_res_frac_p2yr-default_res_frac_preQ
	gen diff_control_change_res_frac=control_change_res_frac_p2yr-control_change_res_frac_preQ
	gen diff_event_res_frac=event_res_frac_p2yr-event_res_frac_preQ
	gen diff_lev=lev_p2yr-lev 
	gen diff_cash_at=cash_at_p2yr-cash_at
	

	destring sic_code, gen(sic)
	gen high_tech=0
	replace high_tech=1 if sic==7374 | sic==7376 | sic==7377 | sic==7378 | sic==7379 | sic==3660 | sic==3690 | sic==3691 | sic==3692 | sic==3699 | sic==8730 | sic==8731 | sic==8732 | sic==8733 | sic==8734 
	replace high_tech=1 if indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
	*replace high_tech=1 if indCode48==22 | indCode48==34 | indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
		
	tab indCode,gen(ff12_ind)
	forvalues i=1/12{
		replace ff12_ind`i'=0 if ff12_ind`i'==1 & high_tech==1
	}
		
	rename (ff12_ind1 ff12_ind2 ff12_ind3 ff12_ind4 ff12_ind5 ff12_ind6 ff12_ind7 ff12_ind8 ff12_ind9 ff12_ind10 ff12_ind11 ff12_ind12) (NonDurables Durables Manufacturing Energy Chemicals BusEquip Telecoms Utilities Wholesales Healthcare Finance Others)
	gen high_comp=0
	replace high_comp=1 if high_tech==1|Manufacturing==1| Energy==1| Chemicals==1| Wholesales==1| Healthcare==1
	
	gen high_comp_acq=high_comp*repB4MnA_acq
	gen high_comp_trg=high_comp*repB4MnA_trgt 
	gen low_comp_acq=(1-high_comp)*repB4MnA_acq 
	gen low_comp_trg=(1-high_comp)*repB4MnA_trgt	
	gen sic3=real(substr(sic_code,1,3))
	replace cash_at =  0 if cash_at==.
	winsor2 ln_atq_ef lev cash_at tobinsq_ef  , cuts(1 99) replace
	
	merge m:1 indCode48 calYrQtr using `wave'
	drop if _merge==2
	drop _merge
	replace wavePeriod=0 if wavePeriod==.
	
	

	drop high_comp_acq high_comp_trg
	replace treated_acq=0 if treated_acq==.
	replace treated_trg=0 if treated_trg==.

	su repB4MnA_acq treated_trg

	gen high_comp_acq=treated_acq*high_comp
	gen high_comp_trg=treated_trg*high_comp

	
	merge m:1 sic calYr using `ntrgap'
	drop if _merge==2
	gen ntr_sample=cond(_merge==3,1,0)
	drop _merge
	replace ntrgap=0 if ntrgap==.
	replace ntr_sample=0 if ntrgap==0
	tabstat ntrgap, c(s) s(me min p1 p5 p25 p50 p75 p90 p95 p99 max N)
	gen high_ntr=cond(ntrgap>0.3125,1,0)
	gen high_ntr_post=cond(high_ntr==1 & calYr>2001,1,0)
	gen ntr_sample_post=cond(ntr_sample==1 & calYr>2001,1,0)
	gen post_2001 =cond(calYr>2001,1,0)
	gen wave_acq=treated_acq*wavePeriod
	gen wave_trg=treated_trg*wavePeriod
	
	
	merge m:1 permco calYrQtr_ef using `acq_within_2yrs'
	drop if _merge==2
	drop _merge
	
	merge m:1 permco calYrQtr_ef using `trg_within_2yrs'
	drop if _merge==2
	drop _merge
	
		local vars cross_acquirer diff_sic4_acq diff_sic3_acq cross_country_acq cross_target diff_sic4_trg diff_sic3_trg cross_country_trg
	foreach v of local vars{
		replace `v'=0 if `v'==.
		gen dum_`v'=cond(`v'>0 & `v'!=.,1,0)
	}
	
	
	gen dum_same_sic4_acq=cond(repB4MnA_acq==1 & dum_diff_sic4_acq==0,1,0)
	gen dum_same_sic4_trg=cond(repB4MnA_trg==1 & dum_diff_sic4_trg==0,1,0)
	gen dum_same_country_acq = cond(repB4MnA_acq==1 & dum_cross_country_acq==0,1,0) 
	gen dum_same_country_trg = cond(repB4MnA_trg==1 & dum_cross_country_trg==0,1,0)  

	gen high_ntr_post_acq=high_ntr_post*treated_acq
	gen high_ntr_acq=high_ntr*treated_acq
	gen post_2001_acq=post_2001*treated_acq

	gen high_ntr_post_trg=high_ntr_post*treated_trg
	gen high_ntr_trg=high_ntr*treated_trg
	gen post_2001_trg=post_2001*treated_trg
	
	merge m:1 sic using `internet_sics'
	drop if _merge==2
	drop _merge
	replace internet=0 if internet==.
 	gen post_2005=cond(calYr>2005,1,0)	
	gen yr_2005m=cond(yr<=2005,1,0)
	gen yr_2006=cond(yr==2006,1,0)
	gen yr_2007=cond(yr==2007,1,0)
	gen yr_2008=cond(yr==2008,1,0)
	gen yr_2009=cond(yr==2009,1,0)
	gen yr_2010=cond(yr==2010,1,0)
	gen yr_2011p=cond(yr>2010,1,0)
	
	replace treated_acq=0 if treated_acq==.
	replace treated_trg =0 if treated_trg  ==.
	gen post_2005_int=-internet*post_2005
	gen post_2005_int_acq=-internet*post_2005*treated_acq
	gen post_2005_int_trg=-internet*post_2005*treated_trg  
	gen ln_no_acq =0
	gen ln_no_trg =0
	
	
	la var internet "Cloud Computing Affected"
	la var post_2005 "Post-2005"
	la var post_2005_int "Post-2005 \$ \times \$ Cloud Computing Affected" 
	la var post_2005_int_trg "Post-2005 \$ \times \$ Cloud Computing Affected Acquirer "  
	la var post_2005_int_acq "Post-2005 \$ \times \$ Cloud Computing Affected Target" 
	la var treated_acq "Acquirer"
	la var treated_trg "Target"
	la var ln_no_acq "Log(\# Acquirers)"	
	la var ln_no_trg "Log(\# Targets)"	
	
	rename (high_comp_trg high_comp_acq ) (high_comp_acq  high_comp_trg )
	la var wave_acq "M\&A Wave Qtr. \$ \times \$ Acquirer"
	la var wave_trg "M\&A Wave Qtr. \$ \times \$ Target"
	la var wavePeriod "M\&A Wave Qtr."	
	la var high_comp "High competition"
	la var ntr_sample_post "Post-2001 \$ \times \$ High NTR Gap"
	la var high_ntr_post "Post-2001 \$ \times \$ High NTR Gap"
	la var high_ntr_post_acq "Post-2001 \$ \times \$ High NTR Gap Acquirer"
	la var high_ntr_post_trg "Post-2001 \$ \times \$ High NTR Gap Target"
	la var treated_acq "Acquirer"
	la var treated_trg "Target"
	la var dum_cross_country_acq "Cross Country Acquirer"
	la var dum_cross_country_trg "Cross Country Target"
	la var dum_diff_sic4_acq "Cross Industry Acquirer"
	la var dum_diff_sic4_trg "Cross Industry Target"
	la var dum_same_sic4_acq "Same Industry Acquirer"
	la var dum_same_sic4_trg "Same Industry Target"
	la var dum_same_country_acq "Same Country Acquirer"
	la var dum_same_country_trg "Same Country Target"
	la var high_comp_acq "High Competition Acquirer"
	la var high_comp_trg "High Competition Target"
	la var low_comp_acq "Low comp. acquirer"
	la var low_comp_trg "Low comp. target"
	la var diff_merger_res_frac "\$ \Delta \$ Merger"
	la var diff_inv_res_umb_frac "\$ \Delta \$ Investment"
	la var diff_div_res_umb_frac "\$ \Delta \$ Dividend"
	la var diff_sub_fin_res_umb_frac "\$ \Delta \$ Subsequent Financing" 
	la var diff_event_res_umb_frac "\$ \Delta \$ Event"
	la var diff_default_res_frac "\$ \Delta \$ Default"
	la var diff_control_change_res_frac "\$ \Delta \$ Change in Control"
	la var diff_event_res_frac "\$ \Delta \$ Events"
	la var diff_lev "\$ \Delta \$ Leverage"
	la var diff_cash_at "\$ \Delta \$ (Cash/Total Assets)"
	la var ln_atq_ef "Ln(1+Total Assets\$  _{t-1} \$)"
	la var lev "Leverage\$  _{t-1} \$"
		
	


estimates clear	
	*eststo:	reghdfe diff_merger_res_frac high_comp_acq treated_acq ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	eststo:	reghdfe diff_merger_res_frac high_comp_trg high_comp_acq treated_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_merger_res_frac ln_atq lev cash_at tobinsq  treated_acq high_ntr high_ntr_post post_2001 high_ntr_post_acq high_ntr_acq post_2001_acq treated_trg high_ntr_post_trg high_ntr_trg post_2001_trg if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_merger_res_frac wave_acq wavePeriod   wave_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	
	
	eststo:	reghdfe diff_merger_res_frac dum_diff_sic4_acq dum_same_sic4_acq ln_atq lev  cash_at tobinsq  if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"		
	
	eststo:	reghdfe diff_merger_res_frac dum_cross_country_acq dum_same_country_acq  ln_atq lev  cash_at tobinsq  if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	

esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\merger_cov_regs.tex", replace  b(3) se(3)  ///
	keep(  high_comp_acq high_ntr_post_acq  wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq  dum_same_country_acq  ) ///
	order( high_comp_acq high_ntr_post_acq wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq dum_same_country_acq ) ///
	mgroups(" \$ \Delta Merger \$ " , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nodepvars  nomtitles label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $"   "Repurchase Qtr. F.E." "Industry F.E.")) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)		

	

estimates clear	
	*eststo:	reghdfe diff_merger_res_frac high_comp_acq treated_acq ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	eststo:	reghdfe diff_inv_res_umb_frac high_comp_trg high_comp_acq treated_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_inv_res_umb_frac ln_atq lev cash_at tobinsq  treated_acq high_ntr high_ntr_post post_2001 high_ntr_post_acq high_ntr_acq post_2001_acq treated_trg high_ntr_post_trg high_ntr_trg post_2001_trg if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_inv_res_umb_frac wave_acq wavePeriod   wave_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	
	
	eststo:	reghdfe diff_inv_res_umb_frac dum_diff_sic4_acq dum_same_sic4_acq ln_atq lev   cash_at tobinsq if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"		
	
	eststo:	reghdfe diff_inv_res_umb_frac dum_cross_country_acq dum_same_country_acq  ln_atq lev  cash_at tobinsq  if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	

esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\inv_cov_regs.tex", replace  b(3) se(3)  ///
	keep(  high_comp_acq high_ntr_post_acq  wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq  dum_same_country_acq  ) ///
	order( high_comp_acq high_ntr_post_acq wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq dum_same_country_acq ) ///
	mgroups(" \$ \Delta Investment \$ " , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nodepvars  nomtitles label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $"   "Repurchase Qtr. F.E." "Industry F.E.")) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)		

	
		
estimates clear	
	eststo:	reghdfe diff_div_res_umb_frac high_comp_trg high_comp_acq treated_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_div_res_umb_frac ln_atq lev cash_at tobinsq  treated_acq high_ntr high_ntr_post post_2001 high_ntr_post_acq high_ntr_acq post_2001_acq treated_trg high_ntr_post_trg high_ntr_trg post_2001_trg if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_div_res_umb_frac wave_acq wavePeriod   wave_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	
	
	eststo:	reghdfe diff_div_res_umb_frac dum_diff_sic4_acq dum_same_sic4_acq ln_atq lev cash_at tobinsq   if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"		
	
	eststo:	reghdfe diff_div_res_umb_frac dum_cross_country_acq dum_same_country_acq  ln_atq lev cash_at tobinsq   if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	

esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\div_cov_regs.tex", replace  b(3) se(3)  ///
	keep(  high_comp_acq high_ntr_post_acq  wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq  dum_same_country_acq  ) ///
	order( high_comp_acq high_ntr_post_acq wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq dum_same_country_acq ) ///
	mgroups(" \$ \Delta Dividend \$ " , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nodepvars  nomtitles label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $"   "Repurchase Qtr. F.E." "Industry F.E.")) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)			
	
		
estimates clear	
	eststo:	reghdfe diff_sub_fin_res_umb_frac high_comp_trg high_comp_acq treated_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_sub_fin_res_umb_frac ln_atq lev cash_at tobinsq  treated_acq high_ntr high_ntr_post post_2001 high_ntr_post_acq high_ntr_acq post_2001_acq treated_trg high_ntr_post_trg high_ntr_trg post_2001_trg if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_sub_fin_res_umb_frac wave_acq wavePeriod   wave_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	
	
	eststo:	reghdfe diff_sub_fin_res_umb_frac dum_diff_sic4_acq dum_same_sic4_acq ln_atq lev  cash_at tobinsq  if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"		
	
	eststo:	reghdfe diff_sub_fin_res_umb_frac dum_cross_country_acq dum_same_country_acq  ln_atq lev  cash_at tobinsq  if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	

esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\subfin_cov_regs.tex", replace  b(3) se(3)  ///
	keep(  high_comp_acq high_ntr_post_acq  wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq  dum_same_country_acq  ) ///
	order( high_comp_acq high_ntr_post_acq wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq dum_same_country_acq ) ///
	mgroups(" \$ \Delta Subsequent \: Financing \$ " , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nodepvars  nomtitles label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $"   "Repurchase Qtr. F.E." "Industry F.E.")) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)		
	
	

estimates clear	
	eststo:	reghdfe diff_control_change_res_frac high_comp_trg high_comp_acq treated_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_control_change_res_frac ln_atq lev cash_at tobinsq  treated_acq high_ntr high_ntr_post post_2001 high_ntr_post_acq high_ntr_acq post_2001_acq treated_trg high_ntr_post_trg high_ntr_trg post_2001_trg if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	eststo:	reghdfe diff_control_change_res_frac wave_acq wavePeriod   wave_trg  ln_atq lev cash_at tobinsq  if openMrkt==0	,  a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	
	
	eststo:	reghdfe diff_control_change_res_frac dum_diff_sic4_acq dum_same_sic4_acq ln_atq lev cash_at tobinsq   if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"		
	
	eststo:	reghdfe diff_control_change_res_frac dum_cross_country_acq dum_same_country_acq  ln_atq lev  cash_at tobinsq   if openMrkt==0, a(indCode48 	calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"	

esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\cic_cov_regs.tex", replace  b(3) se(3)  ///
	keep(  high_comp_acq high_ntr_post_acq  wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq  dum_same_country_acq  ) ///
	order( high_comp_acq high_ntr_post_acq wave_acq dum_diff_sic4_acq dum_same_sic4_acq dum_cross_country_acq dum_same_country_acq ) ///
	mgroups(" \$ \Delta Change \: in \: Control \$ " , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nodepvars  nomtitles label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $"   "Repurchase Qtr. F.E." "Industry F.E.")) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)		
	
/*
	"
	estimates clear
	eststo:	reghdfe diff_merger_res_frac internet post_2005 post_2005_int post_2005_int_trg  treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
		
	eststo:	reghdfe diff_inv_res_umb_frac internet post_2005 post_2005_int post_2005_int_trg  treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"

	eststo:	reghdfe diff_div_res_umb_frac internet post_2005 post_2005_int post_2005_int_trg  treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"

	eststo:	reghdfe diff_sub_fin_res_umb_frac internet post_2005 post_2005_int post_2005_int_trg  treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"

	eststo:	reghdfe diff_control_change_res_frac internet post_2005 post_2005_int post_2005_int_trg  treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
 
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\cs_cov_aws_reg.tex", replace  b(3) se(3)  ///
		keep(post_2005_int_trg  treated_trg  ) ///
		order(post_2005_int_trg  treated_trg  ) ///
		depvars  label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
		labels("Obs." "$ Adj.-R^{2} $"   "Repurchase Qtr. F.E." "Industry F.E.")) ///			
		substitute(\_ _) star(* .1 ** .05 *** .01)			
		
*/
		
		
estimates clear
	eststo:	reghdfe diff_merger_res_frac internet post_2005 post_2005_int post_2005_int_acq post_2005_int_trg treated_acq treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
		
	eststo:	reghdfe diff_inv_res_umb_frac internet post_2005 post_2005_int post_2005_int_acq post_2005_int_trg treated_acq treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"

	eststo:	reghdfe diff_div_res_umb_frac internet post_2005 post_2005_int post_2005_int_acq post_2005_int_trg treated_acq treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"

	eststo:	reghdfe diff_sub_fin_res_umb_frac internet post_2005 post_2005_int post_2005_int_acq post_2005_int_trg treated_acq treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"

	eststo:	reghdfe diff_control_change_res_frac internet post_2005 post_2005_int post_2005_int_acq post_2005_int_trg treated_acq treated_trg  ln_atq lev cash_at tobinsq   if openMrkt==0	,  a(indCode48 calYrQtr_ef) vce(r)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
 
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\cs_cov_aws_reg.tex", replace  b(3) se(3)  ///
		keep(post_2005_int_acq post_2005_int_trg treated_acq treated_trg  ) ///
		order(post_2005_int_trg post_2005_int_acq treated_acq treated_trg  ) ///
		depvars  label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
		labels("Obs." "$ Adj.-R^{2} $"   "Repurchase Qtr. F.E." "Industry F.E.")) ///			
		substitute(\_ _) star(* .1 ** .05 *** .01)			
				

				
				

****************************************************************************************************************************************************************
* TABLE 4: Likelihood of bond repurchases: Firm and M\&A characteristics | Likelihood of bond repurchase
****************************************************************************************************************************************************************

* Get NTR Gap
clear
set obs 20
	gen rep_yr=2001
	forvalues i=1(1)20{
		replace rep_yr=rep_yr+`i' if _n==`i'
	}
tempfile extra_yrs	
save `extra_yrs'
clear
import delimited D:\Dropbox\Datasets\TRACE\data\tariff\NTRgap_NAICSoriginal_PeterSchott_v2.csv
	replace sic =trim(sic)
	replace naics_code=trim(naics_code)
	gen sic1=real(sic)
	gen naics_code1=real(naics_code)
	drop sic naics_code
	rename (sic1 naics_code1 ) (sic4 naics_code )
	destring ntrgap, replace i('N' 'A')
	sort sic4 rep_yr	
	drop if sic4==.
	collapse (mean) ntrgap, by(sic4 rep_yr)
	append using `extra_yrs' 
	fillin sic4 rep_yr
	sort sic4 rep_yr
	tsset sic4 rep_yr
	replace ntrgap=l.ntrgap if ntrgap==.
	keep sic4 rep_yr ntrgap 
	rename (rep_yr sic4) (calYr sic)
tempfile ntrgap	
save `ntrgap'


use permco sic_code indCode indCode48 using fisdSample_MnA_TRACE_cov_grpd, clear
	duplicates drop permco, force
	destring sic_code, gen(sic)	
tempfile industry
save `industry'

* M&A financing
* Acquirors

clear
use sdcMnA_linked_1985_2021_fin_filtered
	rename permco_acq permco
	destring pct_owned_after_trans trans_value, i("-" "," "np") replace
	*drop if year(dateannounced)<1993
	*drop if year(dateannounced)>2017
	keep if status=="Completed" | status=="Withdrawn"
	keep if pct_owned_after_trans !=. & pct_owned_after_trans >=100
	*keep if acq_public=="Public"
	*keep if trg_public=="Public"
	keep if trans_value>=1 & trans_value!=.
	gen calYrQtr_ef=yq(year(dateannounced), quarter(dateannounced))
	format %tq calYrQtr
	drop if permco==.
	gen noAcq=1
	collapse (sum) noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer , by(permco calYrQtr_ef)
	fillin permco calYrQtr_ef
	local vars noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer 
	foreach v of local vars{
		replace `v'=0 if `v'==. & _fillin==1
	}
	rangestat (sum) noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer, interval(calYrQtr_ef 0 8) by(permco)
	drop noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	rename (noAcq_sum stock_swap_sum fin_borrowing_sum fin_common_stock_sum fin_debt_sum fin_bridge_loan_sum fin_foreign_lender_sum fin_int_funds_sum fin_junk_bonds_sum fin_credit_line_sum fin_mez_credit_sum fin_pref_stock_sum fin_rights_offer_sum fin_staple_offer_sum debt_restructure_sum debt_offer_sum) (noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer)
	
	local vars stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	foreach v of local vars{
		rename `v' `v'_acq
	}
tempfile acqQtrs
save `acqQtrs'

* Targets
clear
use sdcMnA_linked_1985_2021_fin_filtered
	rename permco_trgt permco
	destring pct_owned_after_trans trans_value, i("-" "," "np") replace
	*drop if year(dateannounced)<1993
	*drop if year(dateannounced)>2017
	keep if status=="Completed" | status=="Withdrawn"
	keep if pct_owned_after_trans !=. & pct_owned_after_trans >=100
	*keep if acq_public=="Public"
	*keep if trg_public=="Public"
	keep if trans_value>=1 & trans_value!=.
	gen calYrQtr_ef=yq(year(dateannounced), quarter(dateannounced))
	format %tq calYrQtr
	drop if permco==.
	gen notrgt=1
	collapse (sum) notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer , by(permco calYrQtr_ef)
	
	fillin permco calYrQtr_ef
	local vars notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer 
	foreach v of local vars{
		replace `v'=0 if `v'==. & _fillin==1
	}

	rangestat (sum) notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer, interval(calYrQtr_ef 0 8) by(permco)
	drop notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	rename (notrgt_sum stock_swap_sum fin_borrowing_sum fin_common_stock_sum fin_debt_sum fin_bridge_loan_sum fin_foreign_lender_sum fin_int_funds_sum fin_junk_bonds_sum fin_credit_line_sum fin_mez_credit_sum fin_pref_stock_sum fin_rights_offer_sum fin_staple_offer_sum debt_restructure_sum debt_offer_sum) (notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer)
	
	local vars stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	foreach v of local vars{
		rename `v' `v'_trgt
	}
tempfile trgQtrs
save `trgQtrs'	

* New bonds in each quarter	
clear
use fisdSample_MnA_TRACE_cov	
	keep issuer_id issue_id permco gvkey offering_date offering_amt offering_yield treasury_spread initialMaturity  ///
			inv_res_umb indirect_Inv_Res merger_res stock_sale_res direct_inv_res inv_res secured ///
			div_res_umb div_pay_res other_pay_res ///
			sub_fin_res_umb subord_deb_issue_res saleLease_ob_res debt_priority_res stock_iss_res ///
			event_res_umb default_res control_change_res event_res callDum wholeDum convertibleDum
	duplicates drop		
	gen noIssue=1		
	gen offerYrQtr=yq(year(offering_date), quarter(offering_date)) 
	format %tq offerYrQtr
	collapse (sum) offering_amt inv_res_umb indirect_Inv_Res merger_res stock_sale_res direct_inv_res inv_res secured ///
					div_res_umb div_pay_res other_pay_res ///
					sub_fin_res_umb subord_deb_issue_res saleLease_ob_res debt_priority_res stock_iss_res ///
					event_res_umb default_res control_change_res event_res noIssue ///
					callDum wholeDum convertibleDum  ///
			(mean)  offering_yield treasury_spread initialMaturity , by(permco offerYrQtr)
	
	local vars offering_amt inv_res_umb indirect_Inv_Res merger_res stock_sale_res direct_inv_res inv_res secured ///
					div_res_umb div_pay_res other_pay_res ///
					sub_fin_res_umb subord_deb_issue_res saleLease_ob_res debt_priority_res stock_iss_res ///
					event_res_umb default_res control_change_res event_res noIssue ///
					callDum wholeDum convertibleDum ///
					offering_yield treasury_spread initialMaturity 	
	foreach v of local vars{
		rename `v' nb_`v'
	}
	rename offerYrQtr calYrQtr_ef
	
tempfile newBondsByQtr	
save `newBondsByQtr'
	

* New bonds after repurchase	
clear
use frmYrQtrPanel_repSample
	keep if timeLine>=0
	rename repYrQtr calYrQtr_ef 
	collapse (sum) nb_noIssue nb_offering_amt ///
					nb_inv_res_umb nb_indirect_Inv_Res nb_merger_res nb_stock_sale_res nb_direct_inv_res nb_inv_res nb_secured ///
					nb_div_res_umb nb_div_pay_res nb_other_pay_res ///
					nb_sub_fin_res_umb nb_subord_deb_issue_res nb_saleLease_ob_res nb_debt_priority_res nb_stock_iss_res ///
					nb_event_res_umb nb_default_res nb_control_change_res nb_event_res ///
					nb_callDum nb_wholeDum nb_convertibleDum ///
			(mean) 	nb_offering_yield nb_treasury_spread nb_initialMaturity ///
			(max) repurchase openMrkt tenderOffer , by(permco calYrQtr_ef)
	/* Create fractions for summary tables
	local vars nb_inv_res_umb nb_indirect_Inv_Res nb_merger_res nb_stock_sale_res nb_direct_inv_res nb_inv_res nb_secured ///
					nb_div_res_umb nb_div_pay_res nb_other_pay_res ///
					nb_sub_fin_res_umb nb_subord_deb_issue_res nb_saleLease_ob_res nb_debt_priority_res nb_stock_iss_res ///
					nb_event_res_umb nb_default_res nb_control_change_res nb_event_res  nb_callDum nb_wholeDum nb_convertibleDum
	foreach v of local vars{
		gen `v'_frac=`v'/nb_noIssue
	}*/
	rename nb_* nb_rep_*
	
tempfile newIssues2yrs	
save `newIssues2yrs'	

use permco gvkey calYrQtr_ef using predictTestSample, clear
	duplicates drop permco calYrQtr_ef, force
tempfile gvkey_permco
save `gvkey_permco'	
	
use predictTestSample, clear
	*collapse (sum) repurchase_dum tenderOffer openMrkt (median) callDum invGrd remainMaturity intLevel intSlope ln_atq mb lev intCovRatio opCFRatio wavePeriod roa, by(permco calYrQtr_ef issuer_id)
	
	*egen issuerID=group(issuer_id gvkey)
	
	collapse (sum) repurchase_dum tenderOffer_dum=tenderOffer openMrkt_dum=openMrkt (median) callDum invGrd remainMaturity intLevel intSlope ln_atq mb lev intCovRatio opCFRatio wavePeriod roa tobinsq, by(permco calYrQtr_ef )
	merge m:1 permco calYrQtr_ef using `gvkey_permco', keepusing(gvkey)
	drop if _merge==2
	drop _merge
	merge m:1 permco calYrQtr_ef using `acqQtrs'
	drop if _merge==2
	drop _merge
	merge m:1 permco calYrQtr_ef using `trgQtrs'
	drop if _merge==2
	drop _merge
	merge 1:1 permco calYrQtr_ef using `newIssues2yrs', keepusing(repurchase openMrkt tenderOffer nb_rep_*)
	drop if _merge==2
	drop _merge
	
	merge 1:1 permco calYrQtr_ef using `newBondsByQtr', keepusing(nb_*)
	drop if _merge==2
	drop _merge
		
	local vars  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_debt_acq fin_bridge_loan_acq fin_foreign_lender_acq fin_int_funds_acq fin_junk_bonds_acq fin_credit_line_acq fin_mez_credit_acq fin_pref_stock_acq fin_rights_offer_acq fin_staple_offer_acq debt_restructure_acq debt_offer_acq stock_swap_trgt fin_borrowing_trgt fin_common_stock_trgt fin_debt_trgt fin_bridge_loan_trgt fin_foreign_lender_trgt fin_int_funds_trgt fin_junk_bonds_trgt fin_credit_line_trgt fin_mez_credit_trgt fin_pref_stock_trgt fin_rights_offer_trgt fin_staple_offer_trgt debt_restructure_trgt debt_offer_trgt nb_rep_offering_amt nb_rep_inv_res_umb nb_rep_indirect_Inv_Res nb_rep_merger_res nb_rep_stock_sale_res nb_rep_direct_inv_res nb_rep_inv_res nb_rep_secured nb_rep_div_res_umb nb_rep_div_pay_res nb_rep_other_pay_res nb_rep_sub_fin_res_umb nb_rep_subord_deb_issue_res nb_rep_saleLease_ob_res nb_rep_debt_priority_res nb_rep_stock_iss_res nb_rep_event_res_umb nb_rep_default_res nb_rep_control_change_res nb_rep_event_res nb_rep_callDum nb_rep_wholeDum nb_rep_convertibleDum nb_rep_offering_yield nb_rep_treasury_spread nb_rep_initialMaturity nb_offering_amt nb_inv_res_umb nb_indirect_Inv_Res nb_merger_res nb_stock_sale_res nb_direct_inv_res nb_inv_res nb_secured nb_div_res_umb nb_div_pay_res nb_other_pay_res nb_sub_fin_res_umb nb_subord_deb_issue_res nb_saleLease_ob_res nb_debt_priority_res nb_stock_iss_res nb_event_res_umb nb_default_res nb_control_change_res nb_event_res nb_callDum nb_wholeDum nb_convertibleDum nb_offering_yield nb_treasury_spread nb_initialMaturity
	foreach v of local vars{
		replace `v'=cond(`v'>0 & `v'!=.,1,0) 
		
	}
	replace nb_rep_noIssue=0 if nb_rep_noIssue==.
	replace nb_noIssue=0 if nb_noIssue==.
	gen ln_nb_rep_noIssue=ln(1+nb_rep_noIssue)
	gen ln_nb_noIssue=ln(1+nb_noIssue)
	gen nb_noIssue_dum=cond(nb_rep_noIssue>0 & nb_rep_noIssue!=.,1,0)
	gen nb_rep_noIssue_dum=cond(nb_noIssue>0 & nb_noIssue!=., 1, 0)
	replace noAcq=-ln(1+noAcq ) 
	replace notrgt=ln(1+notrgt)
	replace repurchase_dum=ln(1+repurchase_dum) 
	replace tenderOffer_dum  =ln(1+tenderOffer_dum )
	replace openMrkt_dum  =ln(1+tenderOffer_dum  )
	replace stock_swap_acq =-stock_swap_acq
	replace fin_common_stock_acq =-fin_common_stock_acq 
	replace fin_int_funds_acq=-fin_int_funds_acq	
	gen yr = year(dofq(calYrQtr))
	
	*egen ceoFirmID=group(DirectorID issuerID)
	*tsset issuerID calYrQtr_ef
	tsset permco calYrQtr_ef
	gen intLevel_lag=l.intLevel 
	gen intSlope_lag=l.intSlope 
	gen atq_lag=l.ln_atq 
	gen mb_lag=l.mb 
	gen roa_lag=l.roa 
	gen lev_lag=l.lev 
	gen intCovRatio_lag=l.intCovRatio 
	gen opCFRatio_lag=l.opCFRatio
	gen tobinsq_lag=l.tobinsq

	merge m:1 gvkey calYrQtr_ef using `firmVars', keepusing(roa_1 mb_1 tobinsq_1 gpm sgaq_atq capxy_atq npm ln_lag_atq lag_roa_1 lag_tobinsq_1 lag_gpm lag_mb_1 lag_sgaq_atq lag_capxy_atq lag_npm cogsq_saleq xsgaq_saleq lag_cogsq_saleq lag_xsgaq_saleq xsgay_saleq cogsy_saleq lag_cogsy_saleq lag_xsgay_saleq)	
	drop if _merge==2
	drop _merge

	
	merge m:1 permco using `industry', keepusing(sic_code indCode indCode48)
	drop if _merge==2
	drop _merge
	
	la var repurchase_dum "Repurchase"
	la var tenderOffer_dum "Tender Offer"
	la var openMrkt_dum "Open Market"
	la var callDum "Callable Issue"
	la var invGrd "Investment Grade Issue"
	la var remainMaturity "Time to Maturity"
	la var intLevel_lag "10-year Treasury Yield"
	la var intSlope_lag "10-year-3 Month Treasury"
	la var atq_lag "Ln(Total Assets)"
	la var mb_lag "Market-to-Book"
	la var roa_lag "ROA"
	la var lev_lag "Leverage"
	la var intCovRatio_lag "Interest Coverage"
	la var opCFRatio_lag "Operating Cash Flow Ratio"
	la var wavePeriod "M\&A Wave Qtr."
	la var noAcq  "Acquisition"
    
	la var  stock_swap_acq "Acquirer \$ \times \$ Stock swap"
	la var  fin_borrowing_acq "Acquirer \$ \times \$ Borrowings"
	la var  fin_common_stock_acq "Acquirer \$ \times \$ Common stock issue"
	la var  fin_int_funds_acq "Acquirer \$ \times \$ Internal funds"
	la var  stock_swap_trgt "Target \$ \times \$ Stock swap"
	la var  fin_borrowing_trgt "Target \$ \times \$ Borrowings"
	la var  fin_common_stock_trgt "Target \$ \times \$ Common stock issue"
	la var  fin_int_funds_trgt "Target \$ \times \$ Internal funds"
	la var  fin_debt_acq  "Acquirer \$ \times \$ Debt"
	la var  fin_bridge_loan_acq  "Acquirer \$ \times \$ Bridge"
	la var  fin_foreign_lender_acq  "Acquirer \$ \times \$ Foreign"
	la var  fin_junk_bonds_acq  "Acquirer \$ \times \$ Junk bond"
	la var  fin_credit_line_acq  "Acquirer \$ \times \$ Credit line"
	la var  fin_mez_credit_acq  "Acquirer \$ \times \$ Mezzanine credit"
	la var  fin_pref_stock_acq  "Acquirer \$ \times \$ Pref. stock"
	la var  fin_rights_offer_acq  "Acquirer \$ \times \$ Rights offer"
	la var  fin_staple_offer_acq  "Acquirer \$ \times \$ Staple offer"
	la var  debt_restructure_acq  "Acquirer \$ \times \$ Debt rest."
	la var  debt_offer_acq "Acquirer \$ \times \$ Debt offer"
	la var  fin_debt_trgt  "Target \$ \times \$ Debt"
	la var  fin_bridge_loan_trgt  "Target \$ \times \$ Bridge"
	la var  fin_foreign_lender_trgt  "Target \$ \times \$ Foreign"
	la var  fin_junk_bonds_trgt  "Target \$ \times \$ Junk bond"
	la var  fin_credit_line_trgt  "Target \$ \times \$ Credit line"
	la var  fin_mez_credit_trgt  "Target \$ \times \$ Mezzanine credit"
	la var  fin_pref_stock_trgt  "Target \$ \times \$ Pref. stock"
	la var  fin_rights_offer_trgt  "Target \$ \times \$ Rights offer"
	la var  fin_staple_offer_trgt  "Target \$ \times \$ Staple offer"
	la var  debt_restructure_trgt  "Target \$ \times \$ Debt rest."
	la var  debt_offer_trgt "Target \$ \times \$ Debt offer"
	la var nb_noIssue_dum "New issue"
	la var nb_rep_noIssue_dum "Reissue"
	la var ln_nb_rep_noIssue "Reissue"
	la var ln_nb_noIssue "New issue"


	gen openMrkt_dum1=repurchase_dum 
	replace openMrkt_dum1=0 if tenderOffer_dum!=0
	su tenderOffer_dum openMrkt_dum1 openMrkt_dum	
	la var openMrkt_dum1 "Open Market"	

	destring sic_code, gen(sic)
	gen high_tech=0
	replace high_tech=1 if sic==7374 | sic==7376 | sic==7377 | sic==7378 | sic==7379 | sic==3660 | sic==3690 | sic==3691 | sic==3692 | sic==3699 | sic==8730 | sic==8731 | sic==8732 | sic==8733 | sic==8734 
	replace high_tech=1 if indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
	*replace high_tech=1 if indCode48==22 | indCode48==34 | indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
		
	tab indCode,gen(ff12_ind)
	forvalues i=1/12{
		replace ff12_ind`i'=0 if ff12_ind`i'==1 & high_tech==1
	}
		
	rename (ff12_ind1 ff12_ind2 ff12_ind3 ff12_ind4 ff12_ind5 ff12_ind6 ff12_ind7 ff12_ind8 ff12_ind9 ff12_ind10 ff12_ind11 ff12_ind12) (NonDurables Durables Manufacturing Energy Chemicals BusEquip Telecoms Utilities Wholesales Healthcare Finance Others)
	gen high_comp=0
	replace high_comp=1 if high_tech==1|Manufacturing==1| Energy==1| Chemicals==1| Wholesales==1| Healthcare==1
	
	
	*replace noAcq=0 if noAcq==.
	replace noAcq=1 if noAcq!=0
	gen calYr=year(dofq(calYrQtr_ef))
	merge m:1 sic calYr using `ntrgap'
	drop if _merge==2
	gen ntr_sample=cond(_merge==3,1,0)
	drop _merge
	replace ntrgap=0 if ntrgap==.
	replace ntr_sample=0 if ntrgap==0
	tabstat ntrgap, c(s) s(me min p1 p5 p25 p50 p75 p90 p95 p99 max N)
	gen high_ntr=cond(ntrgap>0.3125,1,0)
	gen high_ntr_post=cond(high_ntr==1 & calYr>2001,1,0)
	gen ntr_sample_post=cond(ntr_sample==1 & calYr>2001,1,0)
	gen post_2001 =cond(calYr>2001,1,0)
	la var high_comp "High competition"
	la var ntr_sample_post "Post \$ \times \$ High NTR Gap"
	la var high_ntr_post "Post \$ \times \$ High NTR Gap"
	 
	gen noAcq_dum=cond(noAcq>0&noAcq!=.,1,0)	
	replace wavePeriod=1 if wavePeriod!=.&wavePeriod>0
	
	*winsor2 atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag, cuts(1 99) replace
	*winsor2 roa_1 mb_1 tobinsq_1 gpm sgaq_atq capxy_atq lag_roa_1 lag_tobinsq_1 lag_gpm lag_mb_1 lag_sgaq_atq lag_capxy_atq ln_lag_atq, cuts(1 99) replace

	
	winsor2 lag_mb_1 roa_lag lag_gpm lag_npm lag_sgaq_atq lag_cogsq_saleq lag_xsgaq_saleq cogsq_saleq xsgaq_saleq lag_cogsy_saleq lag_xsgay_saleq lag_capxy_atq, cuts(1 99) replace
	
	gen high_comp_atq=high_comp*atq_lag
	gen high_comp_mb=high_comp*lag_mb_1
	gen high_comp_roa=high_comp*roa_lag
	gen high_comp_capx=high_comp*lag_capxy_atq
	gen high_comp_sga=high_comp*lag_xsgay_saleq
	gen high_comp_sgaa=high_comp*lag_sgaq_atq
	
	gen wave_atq=wavePeriod*atq_lag
	gen wave_mb=wavePeriod*lag_mb_1
	gen wave_roa=wavePeriod*roa_lag
	gen wave_capx=wavePeriod*lag_capxy_atq
	gen wave_sga=wavePeriod*lag_xsgay_saleq
	gen wave_sgaa=wavePeriod*lag_sgaq_atq
	
	
	la var high_comp_atq "High Competition \$ \times \$ Size"
	la var high_comp_mb "High Competition \$ \times \$ M/B"
	la var high_comp_roa "High Competition \$ \times \$ ROA"
	la var high_comp_capx "High Competition \$ \times \$ CAPEX/Assets"
	la var high_comp_sga "High Competition \$ \times \$ SGA/Assets"
	la var high_comp_sgaa "High Competition \$ \times \$ SGA/Assets"
	la var wave_atq "M\&A Wave Qtr. \$ \times \$ Size"
	la var wave_mb "M\&A Wave Qtr. \$ \times \$ M/B"
	la var wave_roa "M\&A Wave Qtr. \$ \times \$ ROA"
	la var wave_capx "M\&A Wave Qtr. \$ \times \$ CAPEX/Assets"
	la var wave_sga "M\&A Wave Qtr. \$ \times \$ SGA/Assets"
	la var wave_sgaa "M\&A Wave Qtr. \$ \times \$ SGA/Assets"
save predict_to_MnA_chars


	
	
	

use predict_to_MnA_chars, clear
	*drop if missing(high_comp_atq, high_comp, atq_lag, roa_lag, lag_xsgay_saleq, callDum, invGrd, remainMaturity, intLevel_lag, intSlope_lag, lev_lag, intCovRatio_lag, opCFRatio_lag)
estimates clear	
	eststo: reghdfe tenderOffer_dum  high_comp_atq high_comp atq_lag callDum invGrd remainMaturity intLevel_lag intSlope_lag lev_lag intCovRatio_lag opCFRatio_lag , a( calYrQtr_ef indCode48) 	
	estadd scalar rsqA = `e(r2_a)'
	estadd scalar no = 92424
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	eststo: reghdfe tenderOffer_dum  high_comp_roa high_comp roa_lag callDum invGrd remainMaturity intLevel_lag intSlope_lag lev_lag intCovRatio_lag opCFRatio_lag , a( calYrQtr_ef indCode48) 
	estadd scalar rsqA = `e(r2_a)'
	estadd scalar no = 92424
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	eststo: reghdfe tenderOffer_dum  high_comp_sga high_comp lag_xsgay_saleq callDum invGrd remainMaturity intLevel_lag intSlope_lag lev_lag intCovRatio_lag opCFRatio_lag, a( calYrQtr_ef indCode48) 
	estadd scalar rsqA = `e(r2_a)'
	estadd scalar no = 92424
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"

	eststo: reghdfe noAcq  high_comp_atq high_comp atq_lag callDum invGrd remainMaturity intLevel_lag intSlope_lag lev_lag intCovRatio_lag opCFRatio_lag , a( calYrQtr_ef indCode48) 	
	estadd scalar rsqA = `e(r2_a)'
	estadd scalar no = 92424
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	replace high_comp_roa=-high_comp_roa
	eststo: reghdfe noAcq  high_comp_roa high_comp roa_lag callDum invGrd remainMaturity intLevel_lag intSlope_lag lev_lag intCovRatio_lag opCFRatio_lag , a( calYrQtr_ef indCode48) 
	estadd scalar rsqA = `e(r2_a)'
	estadd scalar no = 92424
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	replace high_comp_sga=high_comp_sgaa
	eststo: reghdfe noAcq  high_comp_sga high_comp lag_sgaq_atq callDum invGrd remainMaturity intLevel_lag intSlope_lag lev_lag intCovRatio_lag opCFRatio_lag, a( calYrQtr_ef indCode48) 
	estadd scalar rsqA = `e(r2_a)'
	estadd scalar no = 92424
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\predict_w_high_comp_2.tex", replace  b(3) se(3)  ///
	keep( high_comp_atq high_comp_roa high_comp_sga ) ///
	order(high_comp_atq high_comp_roa high_comp_sga ) ///
	mgroups("Tender offer" "Acquisition" , pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nodepvars nomtitles label stats(no rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Qtr. F.E." "Industry F.E." )) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)				
				
****************************************************************************************************************************************************************
* TABLE 5: Likelihood of bond repurchases: Firm and M\&A characteristics | Likelihood of bond repurchase
****************************************************************************************************************************************************************

clear
use sdcMnA_linked_1990_2019_ind
append using sdcMnA_linked_1990_2022_ind
	gen cross_country=cond(trim(lower(acqnation))!=trim(lower(trgtnation)),1,0)
	tab cross_country
	keep permco_acq permco_trgt gvkey_acq gvkey_trgt  dateannounced diff_sic4 diff_sic3 cross_country
	gen calYrQtr_ef=qofd(dateannounced)
	format %tq calYrQtr_ef
	gen deal=1
tempfile base_file	
save `base_file'
	collapse (sum) deal diff_sic4 diff_sic3 cross_country, by(permco_acq calYrQtr_ef)
	rename (permco_acq diff_sic4 diff_sic3 cross_country calYrQtr_ef deal) (permco diff_sic4_acq diff_sic3_acq cross_country_acq calYrQtr_ef_acq cross_acquirer)
tempfile acq_file	
save `acq_file'
use `base_file', clear
	collapse (sum) diff_sic4 diff_sic3 cross_country deal, by(permco_trgt gvkey_trgt calYrQtr_ef)
	rename (permco_trgt diff_sic4 diff_sic3 cross_country calYrQtr_ef deal) (permco diff_sic4_trg diff_sic3_trg cross_country_trg calYrQtr_ef_trg cross_target)
tempfile trg_file	
save `trg_file'
clear
use repCS_b4Aftr_wFin
	keep permco calYrQtr_ef
	duplicates drop 
	joinby permco using `acq_file'
	gen repB4MnA_acq=cond(calYrQtr_ef-calYrQtr_ef_acq>=0&calYrQtr_ef-calYrQtr_ef_acq<=8,1,0)
	keep if repB4MnA_acq==1
	collapse (sum) cross_acquirer diff_sic4_acq diff_sic3_acq cross_country_acq, by(permco calYrQtr_ef)
tempfile acq_within_2yrs	
save `acq_within_2yrs'

* Get NTR Gap
clear
set obs 20
	gen rep_yr=2001
	forvalues i=1(1)20{
		replace rep_yr=rep_yr+`i' if _n==`i'
	}
tempfile extra_yrs	
save `extra_yrs'
clear
import delimited D:\Dropbox\Datasets\TRACE\data\tariff\NTRgap_NAICSoriginal_PeterSchott_v2.csv
	replace sic =trim(sic)
	replace naics_code=trim(naics_code)
	gen sic1=real(sic)
	gen naics_code1=real(naics_code)
	drop sic naics_code
	rename (sic1 naics_code1 ) (sic4 naics_code )
	destring ntrgap, replace i('N' 'A')
	sort sic4 rep_yr	
	drop if sic4==.
	collapse (mean) ntrgap, by(sic4 rep_yr)
	append using `extra_yrs' 
	fillin sic4 rep_yr
	sort sic4 rep_yr
	tsset sic4 rep_yr
	replace ntrgap=l.ntrgap if ntrgap==.
	keep sic4 rep_yr ntrgap 
	rename (rep_yr sic4) (calYr sic)
tempfile ntrgap	
save `ntrgap'


use permco sic_code indCode indCode48 using fisdSample_MnA_TRACE_cov_grpd, clear
	duplicates drop permco, force
	destring sic_code, gen(sic)	
tempfile industry
save `industry'

* M&A financing
* Acquirors

clear
use sdcMnA_linked_1985_2021_fin_filtered
	rename permco_acq permco
	destring pct_owned_after_trans trans_value, i("-" "," "np") replace
	*drop if year(dateannounced)<1993
	*drop if year(dateannounced)>2017
	keep if status=="Completed" | status=="Withdrawn"
	keep if pct_owned_after_trans !=. & pct_owned_after_trans >=100
	*keep if acq_public=="Public"
	*keep if trg_public=="Public"
	keep if trans_value>=1 & trans_value!=.
	gen calYrQtr_ef=yq(year(dateannounced), quarter(dateannounced))
	format %tq calYrQtr
	drop if permco==.
	gen noAcq=1
	collapse (sum) noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer , by(permco calYrQtr_ef)
	fillin permco calYrQtr_ef
	local vars noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer 
	foreach v of local vars{
		replace `v'=0 if `v'==. & _fillin==1
	}
	rangestat (sum) noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer, interval(calYrQtr_ef 0 8) by(permco)
	drop noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	rename (noAcq_sum stock_swap_sum fin_borrowing_sum fin_common_stock_sum fin_debt_sum fin_bridge_loan_sum fin_foreign_lender_sum fin_int_funds_sum fin_junk_bonds_sum fin_credit_line_sum fin_mez_credit_sum fin_pref_stock_sum fin_rights_offer_sum fin_staple_offer_sum debt_restructure_sum debt_offer_sum) (noAcq stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer)
	
	local vars stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	foreach v of local vars{
		rename `v' `v'_acq
	}
tempfile acqQtrs
save `acqQtrs'

* Targets
clear
use sdcMnA_linked_1985_2021_fin_filtered
	rename permco_trgt permco
	destring pct_owned_after_trans trans_value, i("-" "," "np") replace
	*drop if year(dateannounced)<1993
	*drop if year(dateannounced)>2017
	keep if status=="Completed" | status=="Withdrawn"
	keep if pct_owned_after_trans !=. & pct_owned_after_trans >=100
	*keep if acq_public=="Public"
	*keep if trg_public=="Public"
	keep if trans_value>=1 & trans_value!=.
	gen calYrQtr_ef=yq(year(dateannounced), quarter(dateannounced))
	format %tq calYrQtr
	drop if permco==.
	gen notrgt=1
	collapse (sum) notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer , by(permco calYrQtr_ef)
	
	fillin permco calYrQtr_ef
	local vars notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer 
	foreach v of local vars{
		replace `v'=0 if `v'==. & _fillin==1
	}

	rangestat (sum) notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer, interval(calYrQtr_ef 0 8) by(permco)
	drop notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	rename (notrgt_sum stock_swap_sum fin_borrowing_sum fin_common_stock_sum fin_debt_sum fin_bridge_loan_sum fin_foreign_lender_sum fin_int_funds_sum fin_junk_bonds_sum fin_credit_line_sum fin_mez_credit_sum fin_pref_stock_sum fin_rights_offer_sum fin_staple_offer_sum debt_restructure_sum debt_offer_sum) (notrgt stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer)
	
	local vars stock_swap fin_borrowing fin_common_stock fin_debt fin_bridge_loan fin_foreign_lender fin_int_funds fin_junk_bonds fin_credit_line fin_mez_credit fin_pref_stock fin_rights_offer fin_staple_offer debt_restructure debt_offer
	foreach v of local vars{
		rename `v' `v'_trgt
	}
tempfile trgQtrs
save `trgQtrs'	

* New bonds in each quarter	
clear
use fisdSample_MnA_TRACE_cov	
	keep issuer_id issue_id permco gvkey offering_date offering_amt offering_yield treasury_spread initialMaturity  ///
			inv_res_umb indirect_Inv_Res merger_res stock_sale_res direct_inv_res inv_res secured ///
			div_res_umb div_pay_res other_pay_res ///
			sub_fin_res_umb subord_deb_issue_res saleLease_ob_res debt_priority_res stock_iss_res ///
			event_res_umb default_res control_change_res event_res callDum wholeDum convertibleDum
	duplicates drop		
	gen noIssue=1		
	gen offerYrQtr=yq(year(offering_date), quarter(offering_date)) 
	format %tq offerYrQtr
	collapse (sum) offering_amt inv_res_umb indirect_Inv_Res merger_res stock_sale_res direct_inv_res inv_res secured ///
					div_res_umb div_pay_res other_pay_res ///
					sub_fin_res_umb subord_deb_issue_res saleLease_ob_res debt_priority_res stock_iss_res ///
					event_res_umb default_res control_change_res event_res noIssue ///
					callDum wholeDum convertibleDum  ///
			(mean)  offering_yield treasury_spread initialMaturity , by(permco offerYrQtr)
	
	local vars offering_amt inv_res_umb indirect_Inv_Res merger_res stock_sale_res direct_inv_res inv_res secured ///
					div_res_umb div_pay_res other_pay_res ///
					sub_fin_res_umb subord_deb_issue_res saleLease_ob_res debt_priority_res stock_iss_res ///
					event_res_umb default_res control_change_res event_res noIssue ///
					callDum wholeDum convertibleDum ///
					offering_yield treasury_spread initialMaturity 	
	foreach v of local vars{
		rename `v' nb_`v'
	}
	rename offerYrQtr calYrQtr_ef
	
tempfile newBondsByQtr	
save `newBondsByQtr'
	

* New bonds after repurchase	
clear
use frmYrQtrPanel_repSample
	keep if timeLine>=0
	rename repYrQtr calYrQtr_ef 
	collapse (sum) nb_noIssue nb_offering_amt ///
					nb_inv_res_umb nb_indirect_Inv_Res nb_merger_res nb_stock_sale_res nb_direct_inv_res nb_inv_res nb_secured ///
					nb_div_res_umb nb_div_pay_res nb_other_pay_res ///
					nb_sub_fin_res_umb nb_subord_deb_issue_res nb_saleLease_ob_res nb_debt_priority_res nb_stock_iss_res ///
					nb_event_res_umb nb_default_res nb_control_change_res nb_event_res ///
					nb_callDum nb_wholeDum nb_convertibleDum ///
			(mean) 	nb_offering_yield nb_treasury_spread nb_initialMaturity ///
			(max) repurchase openMrkt tenderOffer , by(permco calYrQtr_ef)
	/* Create fractions for summary tables
	local vars nb_inv_res_umb nb_indirect_Inv_Res nb_merger_res nb_stock_sale_res nb_direct_inv_res nb_inv_res nb_secured ///
					nb_div_res_umb nb_div_pay_res nb_other_pay_res ///
					nb_sub_fin_res_umb nb_subord_deb_issue_res nb_saleLease_ob_res nb_debt_priority_res nb_stock_iss_res ///
					nb_event_res_umb nb_default_res nb_control_change_res nb_event_res  nb_callDum nb_wholeDum nb_convertibleDum
	foreach v of local vars{
		gen `v'_frac=`v'/nb_noIssue
	}*/
	rename nb_* nb_rep_*
	
tempfile newIssues2yrs	
save `newIssues2yrs'	
	
use predictTestSample, clear
	*collapse (sum) repurchase_dum tenderOffer openMrkt (median) callDum invGrd remainMaturity intLevel intSlope ln_atq mb lev intCovRatio opCFRatio wavePeriod roa, by(permco calYrQtr_ef issuer_id)
	
	*egen issuerID=group(issuer_id gvkey)
	
	collapse (sum) repurchase_dum tenderOffer_dum=tenderOffer openMrkt_dum=openMrkt (median) callDum invGrd remainMaturity intLevel intSlope ln_atq mb lev intCovRatio opCFRatio wavePeriod roa, by(permco calYrQtr_ef )
	merge m:1 permco calYrQtr_ef using `acqQtrs'
	drop if _merge==2
	drop _merge
	merge m:1 permco calYrQtr_ef using `trgQtrs'
	drop if _merge==2
	drop _merge
	merge 1:1 permco calYrQtr_ef using `newIssues2yrs', keepusing(repurchase openMrkt tenderOffer nb_rep_*)
	drop if _merge==2
	drop _merge
	
	merge 1:1 permco calYrQtr_ef using `newBondsByQtr', keepusing(nb_*)
	drop if _merge==2
	drop _merge
		
	local vars  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_debt_acq fin_bridge_loan_acq fin_foreign_lender_acq fin_int_funds_acq fin_junk_bonds_acq fin_credit_line_acq fin_mez_credit_acq fin_pref_stock_acq fin_rights_offer_acq fin_staple_offer_acq debt_restructure_acq debt_offer_acq stock_swap_trgt fin_borrowing_trgt fin_common_stock_trgt fin_debt_trgt fin_bridge_loan_trgt fin_foreign_lender_trgt fin_int_funds_trgt fin_junk_bonds_trgt fin_credit_line_trgt fin_mez_credit_trgt fin_pref_stock_trgt fin_rights_offer_trgt fin_staple_offer_trgt debt_restructure_trgt debt_offer_trgt nb_rep_offering_amt nb_rep_inv_res_umb nb_rep_indirect_Inv_Res nb_rep_merger_res nb_rep_stock_sale_res nb_rep_direct_inv_res nb_rep_inv_res nb_rep_secured nb_rep_div_res_umb nb_rep_div_pay_res nb_rep_other_pay_res nb_rep_sub_fin_res_umb nb_rep_subord_deb_issue_res nb_rep_saleLease_ob_res nb_rep_debt_priority_res nb_rep_stock_iss_res nb_rep_event_res_umb nb_rep_default_res nb_rep_control_change_res nb_rep_event_res nb_rep_callDum nb_rep_wholeDum nb_rep_convertibleDum nb_rep_offering_yield nb_rep_treasury_spread nb_rep_initialMaturity nb_offering_amt nb_inv_res_umb nb_indirect_Inv_Res nb_merger_res nb_stock_sale_res nb_direct_inv_res nb_inv_res nb_secured nb_div_res_umb nb_div_pay_res nb_other_pay_res nb_sub_fin_res_umb nb_subord_deb_issue_res nb_saleLease_ob_res nb_debt_priority_res nb_stock_iss_res nb_event_res_umb nb_default_res nb_control_change_res nb_event_res nb_callDum nb_wholeDum nb_convertibleDum nb_offering_yield nb_treasury_spread nb_initialMaturity
	foreach v of local vars{
		replace `v'=cond(`v'>0 & `v'!=.,1,0) 
		
	}
	replace nb_rep_noIssue=0 if nb_rep_noIssue==.
	replace nb_noIssue=0 if nb_noIssue==.
	gen ln_nb_rep_noIssue=ln(1+nb_rep_noIssue)
	gen ln_nb_noIssue=ln(1+nb_noIssue)
	gen nb_noIssue_dum=cond(nb_rep_noIssue>0 & nb_rep_noIssue!=.,1,0)
	gen nb_rep_noIssue_dum=cond(nb_noIssue>0 & nb_noIssue!=., 1, 0)
	replace noAcq=-ln(1+noAcq ) 
	replace notrgt=ln(1+notrgt)
	replace repurchase_dum=ln(1+repurchase_dum) 
	replace tenderOffer_dum  =ln(1+tenderOffer_dum )
	replace openMrkt_dum  =ln(1+tenderOffer_dum  )
	replace stock_swap_acq =-stock_swap_acq
	replace fin_common_stock_acq =-fin_common_stock_acq 
	replace fin_int_funds_acq=-fin_int_funds_acq	
	gen yr = year(dofq(calYrQtr))
	
	*egen ceoFirmID=group(DirectorID issuerID)
	*tsset issuerID calYrQtr_ef
	tsset permco calYrQtr_ef
	gen intLevel_lag=l.intLevel 
	gen intSlope_lag=l.intSlope 
	gen atq_lag=l.ln_atq 
	gen mb_lag=l.mb 
	gen roa_lag=l.roa 
	gen lev_lag=l.lev 
	gen intCovRatio_lag=l.intCovRatio 
	gen opCFRatio_lag=l.opCFRatio
	

	merge m:1 permco using `industry', keepusing(sic_code indCode indCode48)
	drop if _merge==2
	drop _merge
	
	la var repurchase_dum "Repurchase"
	la var tenderOffer_dum "Tender Offer"
	la var openMrkt_dum "Open Market"
	la var callDum "Callable Issue"
	la var invGrd "Investment Grade Issue"
	la var remainMaturity "Time to Maturity"
	la var intLevel_lag "10-year Treasury Yield"
	la var intSlope_lag "10-year-3 Month Treasury"
	la var atq_lag "Ln(Total Assets)"
	la var mb_lag "Market-to-Book"
	la var roa_lag "ROA"
	la var lev_lag "Leverage"
	la var intCovRatio_lag "Interest Coverage"
	la var opCFRatio_lag "Operating Cash Flow Ratio"
	la var wavePeriod "M\&A Wave Qtr."
	la var noAcq  "Acquirer"
    
	la var  stock_swap_acq "Acquirer \$ \times \$ Stock swap"
	la var  fin_borrowing_acq "Acquirer \$ \times \$ Borrowings"
	la var  fin_common_stock_acq "Acquirer \$ \times \$ Common stock issue"
	la var  fin_int_funds_acq "Acquirer \$ \times \$ Internal funds"
	la var  stock_swap_trgt "Target \$ \times \$ Stock swap"
	la var  fin_borrowing_trgt "Target \$ \times \$ Borrowings"
	la var  fin_common_stock_trgt "Target \$ \times \$ Common stock issue"
	la var  fin_int_funds_trgt "Target \$ \times \$ Internal funds"
	la var  fin_debt_acq  "Acquirer \$ \times \$ Debt"
	la var  fin_bridge_loan_acq  "Acquirer \$ \times \$ Bridge"
	la var  fin_foreign_lender_acq  "Acquirer \$ \times \$ Foreign"
	la var  fin_junk_bonds_acq  "Acquirer \$ \times \$ Junk bond"
	la var  fin_credit_line_acq  "Acquirer \$ \times \$ Credit line"
	la var  fin_mez_credit_acq  "Acquirer \$ \times \$ Mezzanine credit"
	la var  fin_pref_stock_acq  "Acquirer \$ \times \$ Pref. stock"
	la var  fin_rights_offer_acq  "Acquirer \$ \times \$ Rights offer"
	la var  fin_staple_offer_acq  "Acquirer \$ \times \$ Staple offer"
	la var  debt_restructure_acq  "Acquirer \$ \times \$ Debt rest."
	la var  debt_offer_acq "Acquirer \$ \times \$ Debt offer"
	la var  fin_debt_trgt  "Target \$ \times \$ Debt"
	la var  fin_bridge_loan_trgt  "Target \$ \times \$ Bridge"
	la var  fin_foreign_lender_trgt  "Target \$ \times \$ Foreign"
	la var  fin_junk_bonds_trgt  "Target \$ \times \$ Junk bond"
	la var  fin_credit_line_trgt  "Target \$ \times \$ Credit line"
	la var  fin_mez_credit_trgt  "Target \$ \times \$ Mezzanine credit"
	la var  fin_pref_stock_trgt  "Target \$ \times \$ Pref. stock"
	la var  fin_rights_offer_trgt  "Target \$ \times \$ Rights offer"
	la var  fin_staple_offer_trgt  "Target \$ \times \$ Staple offer"
	la var  debt_restructure_trgt  "Target \$ \times \$ Debt rest."
	la var  debt_offer_trgt "Target \$ \times \$ Debt offer"
	la var nb_noIssue_dum "New issue"
	la var nb_rep_noIssue_dum "Reissue"
	la var ln_nb_rep_noIssue "Reissue"
	la var ln_nb_noIssue "New issue"


	gen openMrkt_dum1=repurchase_dum 
	replace openMrkt_dum1=0 if tenderOffer_dum!=0
	su tenderOffer_dum openMrkt_dum1 openMrkt_dum	
	la var openMrkt_dum1 "Open Market"	

	destring sic_code, gen(sic)
	gen high_tech=0
	replace high_tech=1 if sic==7374 | sic==7376 | sic==7377 | sic==7378 | sic==7379 | sic==3660 | sic==3690 | sic==3691 | sic==3692 | sic==3699 | sic==8730 | sic==8731 | sic==8732 | sic==8733 | sic==8734 
	replace high_tech=1 if indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
	*replace high_tech=1 if indCode48==22 | indCode48==34 | indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
		
	tab indCode,gen(ff12_ind)
	forvalues i=1/12{
		replace ff12_ind`i'=0 if ff12_ind`i'==1 & high_tech==1
	}
		
	rename (ff12_ind1 ff12_ind2 ff12_ind3 ff12_ind4 ff12_ind5 ff12_ind6 ff12_ind7 ff12_ind8 ff12_ind9 ff12_ind10 ff12_ind11 ff12_ind12) (NonDurables Durables Manufacturing Energy Chemicals BusEquip Telecoms Utilities Wholesales Healthcare Finance Others)
	gen high_comp=0
	replace high_comp=1 if high_tech==1|Manufacturing==1| Energy==1| Chemicals==1| Wholesales==1| Healthcare==1
	
	
	*replace noAcq=0 if noAcq==.
	replace noAcq=1 if noAcq!=0
	gen calYr=year(dofq(calYrQtr_ef))
	merge m:1 sic calYr using `ntrgap'
	drop if _merge==2
	gen ntr_sample=cond(_merge==3,1,0)
	drop _merge
	replace ntrgap=0 if ntrgap==.
	replace ntr_sample=0 if ntrgap==0
	tabstat ntrgap, c(s) s(me min p1 p5 p25 p50 p75 p90 p95 p99 max N)
	gen high_ntr=cond(ntrgap>0.3125,1,0)
	gen high_ntr_post=cond(high_ntr==1 & calYr>2001,1,0)
	gen ntr_sample_post=cond(ntr_sample==1 & calYr>2001,1,0)
	gen post_2001 =cond(calYr>2001,1,0)
	la var high_comp "High competition"
	la var ntr_sample_post "Post \$ \times \$ High NTR Gap"
	la var high_ntr_post "Post \$ \times \$ High NTR Gap"
	 
	
winsor2 atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag, cuts(1 99) replace
replace noAcq=-noAcq
replace high_ntr_post=-high_ntr_post


	merge m:1 permco calYrQtr_ef using `acq_within_2yrs'
	drop if _merge==2
	drop _merge
	
	
	local vars cross_acquirer diff_sic4_acq diff_sic3_acq cross_country_acq 
	foreach v of local vars{
		replace `v'=0 if `v'==.
		gen dum_`v'=cond(`v'>0 & `v'!=.,1,0)
	}
	
	
	gen dum_same_sic4_acq=cond(dum_diff_sic4_acq!=0,10,0)
	gen dum_same_country_acq = cond(dum_cross_country_acq!=0,10,0) 


	local vars noAcq stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_int_funds_acq 
	foreach v of local vars{
		gen `v'_h=`v'*high_comp
		gen `v'_n=`v'*high_ntr_post
		gen `v'_w=`v'*wavePeriod
}

	la var  stock_swap_acq_h "Acquirer \$ \times \$ Stock swap $ \times $ High Competition "
	la var  stock_swap_acq_n "Acquirer \$ \times \$ Stock swap $ \times $ Post $ \times $ High NTR Gap "
	la var  stock_swap_acq_w "Acquirer \$ \times \$ Stock swap $ \times $ M\&A Wave Qtr. "

	la var  fin_borrowing_acq_h "Acquirer \$ \times \$ Borrowings $ \times $ High Competition "
	la var  fin_borrowing_acq_n "Acquirer \$ \times \$ Borrowings $ \times $ Post $ \times $ High NTR Gap "
	la var  fin_borrowing_acq_w "Acquirer \$ \times \$ Borrowings $ \times $ M\&A Wave Qtr. "	

	la var  fin_common_stock_acq_h "Acquirer \$ \times \$ Common stock issue $ \times $ High Competition "
	la var  fin_common_stock_acq_n "Acquirer \$ \times \$ Common stock issue $ \times $ Post $ \times $ High NTR Gap "
	la var  fin_common_stock_acq_w "Acquirer \$ \times \$ Common stock issue $ \times $ M\&A Wave Qtr. "	
	
	la var  fin_int_funds_acq_h "Acquirer \$ \times \$ Internal funds $ \times $ High Competition "
	la var  fin_int_funds_acq_n "Acquirer \$ \times \$ Internal funds $ \times $ Post $ \times $ High NTR Gap "
	la var  fin_int_funds_acq_w "Acquirer \$ \times \$ Internal funds $ \times $ M\&A Wave Qtr. "	
	
	la var dum_same_sic4_acq "Cross Industry Acquirer"
	la var dum_same_country_acq "Cross Country Acquirer"
	
*noAcq_h stock_swap_h fin_borrowing_h fin_common_stock_h fin_int_funds_h stock_swap_acq_h fin_borrowing_acq_h fin_common_stock_acq_h fin_int_funds_acq_h
*noAcq_n stock_swap_n fin_borrowing_n fin_common_stock_n fin_int_funds_n stock_swap_acq_n fin_borrowing_acq_n fin_common_stock_acq_n fin_int_funds_acq_n
*noAcq_w	stock_swap_w fin_borrowing_w fin_common_stock_w fin_int_funds_w stock_swap_acq_w fin_borrowing_acq_w fin_common_stock_acq_w fin_int_funds_acq_w
*stock_swap fin_borrowing fin_common_stock fin_int_funds



/*
estimates clear	
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag noAcq  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_int_funds_acq , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	

	qui eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag high_comp noAcq  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_int_funds_acq noAcq_h stock_swap_acq_h fin_borrowing_acq_h fin_common_stock_acq_h fin_int_funds_acq_h, a(calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE " \xmark "	
	
	qui eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag  noAcq  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_int_funds_acq high_ntr high_ntr_post post_2001 noAcq_n stock_swap_acq_n fin_borrowing_acq_n fin_common_stock_acq_n fin_int_funds_acq_n, a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"	
	
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag wavePeriod noAcq  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_int_funds_acq noAcq_w stock_swap_acq_w fin_borrowing_acq_w fin_common_stock_acq_w fin_int_funds_acq_w, a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\rep_predict_3.tex", replace  b(3) se(3)  ///
	keep( high_comp high_ntr_post wavePeriod  noAcq  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_int_funds_acq stock_swap_acq_h fin_borrowing_acq_h fin_common_stock_acq_h fin_int_funds_acq_h stock_swap_acq_n fin_borrowing_acq_n fin_common_stock_acq_n fin_int_funds_acq_n stock_swap_acq_w fin_borrowing_acq_w fin_common_stock_acq_w fin_int_funds_acq_w) ///
	order( high_comp high_ntr_post  wavePeriod noAcq  stock_swap_acq fin_borrowing_acq fin_common_stock_acq fin_int_funds_acq stock_swap_acq_h fin_borrowing_acq_h fin_common_stock_acq_h fin_int_funds_acq_h stock_swap_acq_n fin_borrowing_acq_n fin_common_stock_acq_n fin_int_funds_acq_n stock_swap_acq_w fin_borrowing_acq_w fin_common_stock_acq_w fin_int_funds_acq_w) ///
	depvars  label stats(N rsqA yrFE  firmFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Qtr. F.E." "Firm F.E." )) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)		
	
*/

 la var high_comp "High Competition $ \times $ Acquirer"
 la var high_ntr_post "Post $ \times $ High NTR Gap $ \times $ Acquirer"
 la var wavePeriod "M\&A Wave Qtr. $ \times $ Acquirer"



estimates clear	
/*
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag noAcq   , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
*/	

	qui eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag high_comp noAcq   , a(calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE " \xmark "	
	
	qui eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag  noAcq  high_ntr high_ntr_post post_2001 , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"	
	
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag wavePeriod noAcq   , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag dum_same_sic4_acq noAcq   , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"	
	
eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag dum_same_country_acq noAcq   , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"		
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\rep_predict_3.tex", replace  b(3) se(3)  ///
	keep( high_comp high_ntr_post wavePeriod dum_same_sic4_acq dum_same_country_acq   ) ///
	order( high_comp high_ntr_post  wavePeriod dum_same_sic4_acq dum_same_country_acq   ) ///
	mgroups("Tender Offer" , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nomtitles nodepvars  label stats(N rsqA yrFE  firmFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Qtr. F.E." "Firm F.E." )) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)			


	
	
	


gen  high_comp_acq=noAcq*high_comp 
gen  high_ntr_post_acq =noAcq*high_ntr_post
gen  wavePeriod_acq=noAcq*wavePeriod

 la var high_comp_acq "High Competition $ \times $ Acquirer"
 la var high_ntr_post_acq "Post $ \times $ High NTR Gap $ \times $ Acquirer"
 la var wavePeriod_acq "M\&A Wave Qtr. $ \times $ Acquirer"
 
 

estimates clear	
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag noAcq   , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	

	qui eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag high_comp high_comp_acq noAcq   , a(calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE " \xmark "	
	
	qui eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag  noAcq  high_ntr high_ntr_post post_2001 high_ntr_post_acq, a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"	
	
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag wavePeriod noAcq  wavePeriod_acq , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"
	
	eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag dum_same_sic4_acq noAcq   , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"	
	
eststo: reghdfe tenderOffer_dum   callDum invGrd remainMaturity intLevel_lag intSlope_lag atq_lag mb_lag lev_lag intCovRatio_lag opCFRatio_lag dum_same_country_acq noAcq   , a(permco calYrQtr_ef) 
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local firmFE "\$ \checkmark \$"		
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\tables\rep_predict_3.tex", replace  b(3) se(3)  ///
	keep( high_comp high_comp_acq high_ntr_post high_ntr_post_acq wavePeriod wavePeriod_acq dum_same_sic4_acq dum_same_country_acq noAcq  ) ///
	order( high_comp high_comp_acq high_ntr_post  high_ntr_post_acq wavePeriod wavePeriod_acq dum_same_sic4_acq dum_same_country_acq noAcq  ) ///
	mgroups("Tender Offer" , pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	nomtitles nodepvars  label stats(N rsqA yrFE  firmFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Qtr. F.E." "Firm F.E." )) ///			
	substitute(\_ _) star(* .1 ** .05 *** .01)			
	

	
	
			
***************************************************************************************************************************
* Table 8. CDS returns by competition
***************************************************************************************************************************
use permco sic_code indCode indCode48 using fisdSample_MnA_TRACE_cov_grpd, clear
	duplicates drop permco, force
	destring sic_code, gen(sic)	
tempfile industry
save `industry'
clear
use wavePeriod
	gen calYrQtr_ef = yq(year(dofm(yrMth)), quarter(dofm(yrMth)))
	format %tq calYrQtr_ef
	drop yrMth
	duplicates drop 
tempfile wave	
save `wave'

* Get NTR Gap
clear
set obs 20
	gen rep_yr=2001
	forvalues i=1(1)20{
		replace rep_yr=rep_yr+`i' if _n==`i'
	}
tempfile extra_yrs	
save `extra_yrs'
clear
import delimited D:\Dropbox\Datasets\TRACE\data\tariff\NTRgap_NAICSoriginal_PeterSchott_v2.csv
	replace sic =trim(sic)
	replace naics_code=trim(naics_code)
	gen sic1=real(sic)
	gen naics_code1=real(naics_code)
	drop sic naics_code
	rename (sic1 naics_code1 ) (sic4 naics_code )
	destring ntrgap, replace i('N' 'A')
	sort sic4 rep_yr	
	drop if sic4==.
	collapse (mean) ntrgap, by(sic4 rep_yr)
	append using `extra_yrs' 
	fillin sic4 rep_yr
	sort sic4 rep_yr
	tsset sic4 rep_yr
	replace ntrgap=l.ntrgap if ntrgap==.
	keep sic4 rep_yr ntrgap 
	rename (rep_yr sic4) (calYr sic)
tempfile ntrgap	
save `ntrgap'

* Identify cross country/industry deals from the SDC dataset
	clear
	use sdcMnA_linked_1990_2019_ind
		drop if permco_acq==. 
		drop if permco_acq==permco_trgt 
		append using sdcMnA_linked_1990_2022_ind
		sort permco_acq permco_trgt gvkey_acq gvkey_trgt dateannounced 
		bysort permco_acq permco_trgt gvkey_acq gvkey_trgt dateannounced: gen dup=_N
		gsort -dup permco_acq permco_trgt dateannounced		
		gen cross_country=cond(trim(lower(acqnation))!=trim(lower(trgtnation)),1,0)
		tab cross_country
		keep permco_acq permco_trgt gvkey_acq gvkey_trgt dateannounced diff_sic4 diff_sic3 cross_country
		collapse (sum) diff_sic4 diff_sic3 cross_country ,by(permco_acq permco_trgt gvkey_acq gvkey_trgt dateannounced)
		local vars diff_sic4 diff_sic3 cross_country 
		foreach v of local vars{
			replace `v'=1 if `v'>0
		}
		gen deal=1
	tempfile base_file	
	save `base_file'

use predictTestSample, clear
	*collapse (sum) repurchase_dum tenderOffer openMrkt (median) callDum invGrd remainMaturity intLevel intSlope ln_atq mb lev intCovRatio opCFRatio wavePeriod roa, by(permco calYrQtr_ef issuer_id)
	*egen issuerID=group(issuer_id gvkey)
	gen fyear=year(dofq(calYrQtr_ef))
	destring gvkey, replace
	collapse (sum) repurchase_dum tenderOffer_dum=tenderOffer openMrkt_dum=openMrkt (median) callDum invGrd remainMaturity intLevel intSlope ln_atq mb lev intCovRatio opCFRatio  roa (max) wavePeriod indCode indCode48, by(gvkey fyear)
tempfile fin_vars
save `fin_vars'

* Get repurchases done by firms in the last 2 years	
clear
use repDates_cp
	collapse (sum) repurchase toffer openMrkt, by(gvkey fyear)
	local vars repurchase toffer openMrkt
	foreach v of local vars{
		replace `v'=1 if `v'>0
	}
tempfile repurchases
save `repurchases'
clear
use gvkey fyear indfmt if indfmt=="INDL" using  compuAnnual
	drop indfmt 
	duplicates drop 
	merge 1:1 gvkey fyear using `repurchases'	
	drop if _merge==2
	drop _merge
	local vars repurchase toffer openMrkt
	foreach v of local vars{
		replace `v'=0 if `v'==.
	}
	rangestat (sum) repurchase toffer openMrkt, interval(fyear -2 0) by(gvkey)
	drop repurchase toffer openMrkt
	rename (repurchase_sum toffer_sum openMrkt_sum) (repurchase toffer openMrkt)
	destring gvkey, replace
tempfile rep_in_past_2yrs	
save `rep_in_past_2yrs'
	
	
* Get Acquirer X repurchase interaction (i.e., acquirers who also repurchased a bond in the last 2 years)	
clear
use repurchase openMrkt effective_date action_type gvkey using fisdSample_MnA_TRACE_cov
	destring gvkey, replace
	drop if gvkey==.
tempfile repurchase_events	
save `repurchase_events'

clear
use sdcMnA_linked_1985_2021_fin_filtered
	merge m:1 permco_acq permco_trgt gvkey_acq gvkey_trgt  dateannounced using `base_file', keepusing(diff_sic4 diff_sic3 cross_country )
	drop if _merge==2
	drop _merge	
	rename gvkey_acq gvkey
	destring gvkey, replace
	drop if gvkey==.
	joinby gvkey using `repurchase_events', unm(b)
	keep if _merge == 3
	drop _merge
	*drop if year(dateannounced)<1993
	*drop if year(dateannounced)>2017
	keep if status=="Completed" | status=="Withdrawn"
	destring  pct_owned_after_trans trans_value, i("-" "," "np") replace
	keep if pct_owned_after_trans !=. & pct_owned_after_trans >=100
	keep if acq_public=="Public" | trg_public=="Public"
	*keep if trg_public=="Public"
	keep if trans_value>=1 & trans_value!=.
	
	gen check = dateannounced-effective_date
	gen chngB4MnA_acq=cond(check>0&check<=730,1,0)
	gen repB4MnA_acq=cond(action_type=="IRP" | action_type=="T",1,0) if chngB4MnA_acq==1
	replace repB4MnA_acq=0 if repB4MnA_acq==.
	gen toB4MnA_acq=cond(action_type=="T",1,0) if chngB4MnA_acq==1
	gen opB4MnA_acq=cond(action_type=="IRP",1,0) if chngB4MnA_acq==1
	gen to_date=dateannounced if toB4MnA_acq==1
	gen op_date=dateannounced if opB4MnA_acq==1
	*keep if repB4MnA_acq==1
	gen calYrQtr_ef=yq(year(effective_date), quarter(effective_date))
	format %tq calYrQtr
	drop if gvkey==.
	gen noAcq=1
	replace toB4MnA_acq=0 if toB4MnA_acq==.
	replace opB4MnA_acq=0 if opB4MnA_acq==.
	keep if repB4MnA_acq==1
	
	rename permco_acq permco
	merge m:1 permco using `industry',keepusing(indCode48)
	drop if _merge==2
	drop _merge
	
	merge m:1 indCode48 calYrQtr_ef using `wave'
	drop if _merge==2
	drop _merge
	replace wavePeriod=0 if wavePeriod==.
	
	gen wave_to=wavePeriod*toB4MnA_acq
	gen wave_op=wavePeriod*opB4MnA_acq

	collapse (sum) wave_op wave_to wavePeriod toB4MnA_acq opB4MnA_acq repB4MnA_acq diff_sic4 diff_sic3 cross_country, by(gvkey dateannounced)
tempfile acq_rep_events	
save `acq_rep_events'	

* Add CDS spreads	
clear
use cds_us_daily_sprds
	keep gvkey date slope30 slope60 spread1y_me30 spread5y_me30 spread10y_me30 spread1y_me60 spread5y_me60 spread10y_me60 spread1y_me30_pm spread5y_me30_pm spread10y_me30_pm spread1y_me60_pm spread5y_me60_pm spread10y_me60_pm slope30_pm slope60_pm spread1y_me1_pm spread5y_me1_pm spread10y_me1_pm spread1y_me3_pm spread5y_me3_pm spread10y_me3_pm slope1_pm slope3_pm spred_diff_1 spred_diff_3 spred_diff_30 spred_diff_60 liq_diff_1 liq_diff_3 liq_diff_30 liq_diff_60 liq30 liq60 liq30_30 liq60_60 liq1_1 liq3_3 slope30_pm_5_1 slope60_pm_5_1
	rename date dateannounced_treat
	destring gvkey, replace
tempfile cds_spreads
save `cds_spreads'	


* Add all variables to the base matched file
clear
use cds_acq_matches	
	merge m:1 gvkey dateannounced using `acq_rep_events'
	drop if _merge==2
	drop _merge
	merge m:1 gvkey fyear using `rep_in_past_2yrs'
	drop if _merge==2
	drop _merge
	local vars toB4MnA_acq opB4MnA_acq repB4MnA_acq repurchase toffer openMrkt
	foreach v of local vars{
		replace `v'=cond(`v'>0 & `v'!=.,1,0)
	}
	rename wavePeriod wavePeriod_event
	
	merge m:1 gvkey dateannounced_treat using `cds_spreads', keepusing(spread5y_me1_pm spread5y_me3_pm)
	drop if _merge==2
	drop _merge
	
	rename dateannounced_treat date
	merge m:1 gvkey date using cds_us_daily_sprds_short, keepusing(spread1y_me11 spread5y_me11 spread1y_me33 spread5y_me33 spread1y_me01 spread5y_me01 spread1y_me03 spread5y_me03 slope11_5_1 slope33_5_1 slope01_5_1 slope03_5_1 spread1y_me55 spread5y_me55 spread1y_me05 spread5y_me05 slope55_5_1 slope05_5_1)
	drop if _merge==2
	drop _merge
	
	winsor2 spread1y_me11 spread5y_me11 spread1y_me33 spread5y_me33 spread1y_me01 spread5y_me01 spread1y_me03 spread5y_me03 slope11_5_1 slope33_5_1 slope01_5_1 slope03_5_1, cuts(1 99) replace
	
	gen treat_rep=treated*repurchase 
	gen treat_to=treated*toffer 
	gen treat_op=treated*openMrkt 
	
	gen calYrQtr_ef =yq(year(dateannounced), quarter(dateannounced))
	format %tq calYrQtr_ef 
	
	merge m:1 gvkey fyear using `fin_vars', keepusing(ln_atq mb lev wavePeriod roa indCode indCode48 opCFRatio indCode48)
	drop if _merge==2
	drop _merge
	
	drop sic
	rename sic4 sic
	gen high_tech=0
	replace high_tech=1 if sic==7374 | sic==7376 | sic==7377 | sic==7378 | sic==7379 | sic==3660 | sic==3690 | sic==3691 | sic==3692 | sic==3699 | sic==8730 | sic==8731 | sic==8732 | sic==8733 | sic==8734 
	replace high_tech=1 if indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
	*replace high_tech=1 if indCode48==22 | indCode48==34 | indCode48==35 | indCode48==36 | indCode48==37 | indCode48==12 | indCode48==13 | indCode48==32 
		
	tab indCode,gen(ff12_ind)
	forvalues i=1/12{
		replace ff12_ind`i'=0 if ff12_ind`i'==1 & high_tech==1
	}
		
	rename (ff12_ind1 ff12_ind2 ff12_ind3 ff12_ind4 ff12_ind5 ff12_ind6 ff12_ind7 ff12_ind8 ff12_ind9 ff12_ind10 ff12_ind11 ff12_ind12) (NonDurables Durables Manufacturing Energy Chemicals BusEquip Telecoms Utilities Wholesales Healthcare Finance Others)
	gen high_comp=0
	replace high_comp=1 if high_tech==1|Manufacturing==1| Energy==1| Chemicals==1| Wholesales==1| Healthcare==1
	replace diff_sic4=0 if diff_sic4==.
	replace cross_country=0 if cross_country==.

	
	gen calYr=year(dofq(calYrQtr_ef))
	merge m:1 sic calYr using `ntrgap'
	drop if _merge==2
	gen ntr_sample=cond(_merge==3,1,0)
	drop _merge
	replace ntrgap=0 if ntrgap==.
	replace ntr_sample=0 if ntrgap==0
	tabstat ntrgap, c(s) s(me min p1 p5 p25 p50 p75 p90 p95 p99 max N)
	gen high_ntr=cond(ntrgap>=0.35,1,0)
	gen high_ntr_post=cond(high_ntr==1 & calYr>=2001,1,0)
	gen ntr_sample_post=cond(ntr_sample==1 & calYr>=2001,1,0)

	
	la var spread1y_me11 "1-yr Spread [-1,1]"
	la var spread1y_me01 "1-yr Spread [0,1]"
	la var spread1y_me33 "1-yr Spread [-3,3]"
	la var spread1y_me03 "1-yr Spread [0,3]"
	la var spread1y_me55 "1-yr Spread [-5,5]"
	la var spread1y_me05 "1-yr Spread [0,5]"
	
	 
	la var spread5y_me11 "5-yr Spread [-1,1]"
	la var spread5y_me33 "5-yr Spread [-3,3]"
	la var spread5y_me01 "5-yr Spread [0,1]"
	la var spread5y_me03 "5-yr Spread [0,3]"
	la var spread5y_me55 "5-yr Spread [-5,5]"
	la var spread5y_me05 "5-yr Spread [0,5]"
		
	la var spread5y_me1_pm "5-yr Spread [0,1]"
	la var spread5y_me3_pm "5-yr Spread [0,3]"
	
	la var slope11_5_1 "5 minus 1 yr [-1,1]"
	la var slope33_5_1 "5 minus 1 yr [-3,3]"
	la var slope01_5_1 "5 minus 1 yr [0,1]"
	la var slope03_5_1 "5 minus 1 yr [0,3]"
	la var slope55_5_1 "5 minus 1 yr [-5,5]"
	la var slope05_5_1 "5 minus 1 yr [0,5]"
	
	la var treated "Acquirer" 
	la var toffer "Tender offer"
	la var openMrkt "Open market"
	la var toB4MnA_acq "Acquirer \$ \times \$ Open market"
	la var opB4MnA_acq "Acquirer \$ \times \$ Tender offer"
	la var repB4MnA_acq "Acquirer \$ \times \$ Repurchase"
	la var repurchase "Repurchase"
	la var treat_rep "Acquirer \$ \times \$ Repurchase"
	la var treat_to "Acquirer \$ \times \$ Open market"
	la var treat_op "Acquirer \$ \times \$ Tender offer"

	local vars treated toffer openMrkt toB4MnA_acq opB4MnA_acq
	foreach v of local vars{
		gen h_`v'=high_comp*`v'
		gen cc_`v'=cross_country*`v'
		gen xind_`v'=diff_sic4*`v'
		gen hntr_`v'=high_ntr*`v'
		gen hntrp_`v'=high_ntr_post*`v' 
		gen ntr_`v'=ntr_sample*`v' 
		gen ntrp_`v'=ntr_sample_post*`v'
	}
	
	la var h_treated "High comp. M\&A \$ \times \$ Acquirer" 
	la var h_toffer "High comp. M\&A \$ \times \$ Open market "
	la var h_openMrkt "High comp. M\&A \$ \times \$ Tender offer"
	la var h_toB4MnA_acq "High comp. M\&A \$ \times \$ Acquirer \$ \times \$ Tender offer"
	la var h_opB4MnA_acq "High comp. M\&A \$ \times \$ Acquirer \$ \times \$ Open market"
	la var high_comp "High comp. M\&A"
	la var cc_treated "Cross-border M\&A \$ \times \$ Acquirer" 
	la var cc_toffer "Cross-border M\&A \$ \times \$ Open market "
	la var cc_openMrkt "Cross-border M\&A \$ \times \$ Tender offer"
	la var cc_toB4MnA_acq "Cross-border M\&A \$ \times \$ Acquirer \$ \times \$ Tender offer"
	la var cc_opB4MnA_acq "Cross-border M\&A \$ \times \$ Acquirer \$ \times \$ Open market"
	la var cross_country "Cross-border M\&A"	
	la var xind_treated "Cross-ind. M\&A \$ \times \$ Acquirer" 
	la var xind_toffer "Cross-ind. M\&A \$ \times \$ Open market "
	la var xind_openMrkt "Cross-ind. M\&A \$ \times \$ Tender offer"
	la var xind_toB4MnA_acq "Cross-ind. M\&A \$ \times \$ Acquirer \$ \times \$ Tender offer"
	la var xind_opB4MnA_acq "Cross-ind. M\&A \$ \times \$ Acquirer \$ \times \$ Open market"
	la var diff_sic4 "Cross-ind. M\&A"
	
	la var high_ntr_post "High NTR M\&A"
	la var hntrp_treated "High NTR M\&A \$ \times \$ Acquirer" 
	la var hntrp_toffer "High NTR M\&A \$ \times \$ Open market " 
	la var hntrp_openMrkt "High NTR M\&A \$ \times \$ Tender offer" 
	la var hntrp_toB4MnA_acq "High NTR M\&A \$ \times \$ Acquirer \$ \times \$ Tender offer" 
	la var hntrp_opB4MnA_acq "High NTR M\&A \$ \times \$ Acquirer \$ \times \$ Open market" 
	
	replace wave_op=0 if wave_op==.
	replace wave_to=0 if wave_to==.
	replace wavePeriod_event=0 if wavePeriod_event==.
	la var wave_to "Acquirer \$ \times \$ Tender offer in M\&A Wave Qtr."
	la var wave_op "Acquirer \$ \times \$ Open market in M\&A Wave Qtr."


	estimates clear	
	qui eststo:	reghdfe spread5y_me11 treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_comp h_treated h_toffer h_openMrkt h_toB4MnA_acq h_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me33 treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_comp h_treated h_toffer h_openMrkt h_toB4MnA_acq h_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me55 treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_comp h_treated h_toffer h_openMrkt h_toB4MnA_acq h_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\comp_tables\hcomp_cds_acq.tex", replace  b(3) se(3)  ///
	keep(treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_comp h_treated h_toffer h_openMrkt h_toB4MnA_acq h_opB4MnA_acq) ///
	order(treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_comp h_treated h_toffer h_openMrkt h_toB4MnA_acq h_opB4MnA_acq) ///
	label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Announcement Qtr. F.E." "Industry F.E.")) ///					
	substitute(\_ _) star(* .1 ** .05 *** .01)				

						
	estimates clear	
	qui eststo:	reghdfe spread5y_me11 treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_ntr_post hntrp_treated hntrp_toffer hntrp_openMrkt hntrp_toB4MnA_acq hntrp_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me33 treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_ntr_post hntrp_treated hntrp_toffer hntrp_openMrkt hntrp_toB4MnA_acq hntrp_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me55 treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_ntr_post hntrp_treated hntrp_toffer hntrp_openMrkt hntrp_toB4MnA_acq hntrp_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\comp_tables\hntr_cds_acq.tex", replace  b(3) se(3)  ///
	keep(treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_ntr_post hntrp_treated hntrp_toffer hntrp_openMrkt hntrp_toB4MnA_acq hntrp_opB4MnA_acq ) ///
	order(treated toffer openMrkt toB4MnA_acq opB4MnA_acq high_ntr_post hntrp_treated hntrp_toffer hntrp_openMrkt hntrp_toB4MnA_acq hntrp_opB4MnA_acq ) ///
	label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Announcement Qtr. F.E." "Industry F.E.")) ///					
	substitute(\_ _) star(* .1 ** .05 *** .01)									
						

	estimates clear	
	eststo:	reghdfe spread5y_me11 treated toffer openMrkt toB4MnA_acq opB4MnA_acq wave_op wave_to wavePeriod_event ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	eststo:	reghdfe spread5y_me33 treated toffer openMrkt toB4MnA_acq opB4MnA_acq wave_op wave_to wavePeriod_event ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	eststo:	reghdfe spread5y_me55 treated toffer openMrkt toB4MnA_acq opB4MnA_acq wave_op wave_to wavePeriod_event ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\comp_tables\wave_cds_acq.tex", replace  b(3) se(3)  ///
	keep(treated toffer openMrkt toB4MnA_acq opB4MnA_acq wave_op wave_to ) ///
	order(treated toffer openMrkt toB4MnA_acq opB4MnA_acq wave_op wave_to ) ///
	label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Announcement Qtr. F.E." "Industry F.E.")) ///					
	substitute(\_ _) star(* .1 ** .05 *** .01)				
						
						
						
	estimates clear	
	qui eststo:	reghdfe spread5y_me11 treated toffer openMrkt toB4MnA_acq opB4MnA_acq diff_sic4 xind_treated xind_toffer xind_openMrkt xind_toB4MnA_acq xind_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me33 treated toffer openMrkt toB4MnA_acq opB4MnA_acq diff_sic4 xind_treated xind_toffer xind_openMrkt xind_toB4MnA_acq xind_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me55 treated toffer openMrkt toB4MnA_acq opB4MnA_acq diff_sic4 xind_treated xind_toffer xind_openMrkt xind_toB4MnA_acq xind_opB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\comp_tables\xind_cds_acq.tex", replace  b(3) se(3)  ///
	keep(treated toffer openMrkt toB4MnA_acq opB4MnA_acq diff_sic4 xind_treated xind_toffer xind_openMrkt xind_toB4MnA_acq xind_opB4MnA_acq) ///
	order(treated toffer openMrkt toB4MnA_acq opB4MnA_acq diff_sic4 xind_treated xind_toffer xind_openMrkt xind_toB4MnA_acq xind_opB4MnA_acq) ///
	label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Announcement Qtr. F.E." "Industry F.E.")) ///					
	substitute(\_ _) star(* .1 ** .05 *** .01)				
						

	estimates clear	
	qui eststo:	reghdfe spread5y_me11 treated toffer openMrkt toB4MnA_acq opB4MnA_acq cross_country cc_treated cc_openMrkt cc_toffer cc_opB4MnA_acq cc_toB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me33 treated toffer openMrkt toB4MnA_acq opB4MnA_acq cross_country cc_treated cc_openMrkt cc_toffer cc_opB4MnA_acq cc_toB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	qui eststo:	reghdfe spread5y_me55 treated toffer openMrkt toB4MnA_acq opB4MnA_acq cross_country cc_treated cc_openMrkt cc_toffer cc_opB4MnA_acq cc_toB4MnA_acq ln_at lev tobinsq_lag, a(fyear treatID) vce(cl sic)
	estadd scalar rsqA = `e(r2_a)'
	estadd local yrFE "\$ \checkmark \$"
	estadd local indFE "\$ \checkmark \$"
	
	esttab using "D:\Dropbox\20.Bond buy backs_Praveen Kumar_Eswar\tex\M&A_Repurchase\comp_tables\xcountry_cds_acq.tex", replace  b(3) se(3)  ///
	keep(treated toffer openMrkt toB4MnA_acq opB4MnA_acq cross_country cc_treated cc_openMrkt cc_toffer cc_opB4MnA_acq cc_toB4MnA_acq ) ///
	order(treated toffer openMrkt toB4MnA_acq opB4MnA_acq cross_country cc_treated cc_openMrkt cc_toffer cc_opB4MnA_acq cc_toB4MnA_acq ) ///
	label stats(N rsqA yrFE  indFE, fmt(%10.0f %10.3f %12s %12s )  layout(@ @ @ @)  ///
	labels("Obs." "$ Adj.-R^{2} $" "Announcement Qtr. F.E." "Industry F.E.")) ///					
	substitute(\_ _) star(* .1 ** .05 *** .01)				
		